Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf: avoid double checking value0 Future. #10972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions project/MimaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object MimaFilters extends AutoPlugin {
object autoImport {
val mimaReferenceVersion = settingKey[Option[String]]("Scala version number to run MiMa against")
}

import autoImport._

override val globalSettings = Seq(
Expand Down Expand Up @@ -41,17 +42,20 @@ object MimaFilters extends AutoPlugin {

// KEEP: the CommonErrors object is not a public API
ProblemFilters.exclude[MissingClassProblem]("scala.collection.generic.CommonErrors"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.generic.CommonErrors$")
ProblemFilters.exclude[MissingClassProblem]("scala.collection.generic.CommonErrors$"),

//ADD: Await#CompletedFuture is not a public API
ProblemFilters.exclude[MissingClassProblem]("scala.concurrent.Await$CompletedFuture$")
)

override val buildSettings = Seq(
mimaFailOnNoPrevious := false, // we opt everything out, knowing we only check library/reflect
)

val mimaSettings: Seq[Setting[_]] = Def.settings(
mimaPreviousArtifacts := mimaReferenceVersion.value.map(organization.value % name.value % _).toSet,
mimaCheckDirection := "both",
mimaBinaryIssueFilters ++= mimaFilters,
// mimaReportSignatureProblems := true, // TODO: enable
mimaPreviousArtifacts := mimaReferenceVersion.value.map(organization.value % name.value % _).toSet,
mimaCheckDirection := "both",
mimaBinaryIssueFilters ++= mimaFilters,
// mimaReportSignatureProblems := true, // TODO: enable
)
}
11 changes: 9 additions & 2 deletions src/library/scala/concurrent/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ package object concurrent {
}

package concurrent {

import scala.util.Try

/**
* This marker trait is used by [[Await]] to ensure that [[Awaitable.ready]] and [[Awaitable.result]]
* are not directly called by user code. An implicit instance of this trait is only available when
Expand Down Expand Up @@ -170,7 +173,7 @@ package concurrent {
@throws(classOf[TimeoutException])
@throws(classOf[InterruptedException])
final def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = awaitable match {
case f: Future[T] if f.isCompleted => awaitable.ready(atMost)(AwaitPermission)
case f: Future[T] if f.isCompleted => awaitable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we still want to validate the duration

#7767 was closed for that reason, in favor of #7768

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just back from hometown , will check this weekend

case _ => blocking(awaitable.ready(atMost)(AwaitPermission))
}

Expand All @@ -197,8 +200,12 @@ package concurrent {
@throws(classOf[TimeoutException])
@throws(classOf[InterruptedException])
final def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable match {
case f: Future[T] if f.isCompleted => f.result(atMost)(AwaitPermission)
case CompletedFuture(result: Try[T] @unchecked) => result.get
case _ => blocking(awaitable.result(atMost)(AwaitPermission))
}

private final object CompletedFuture {
def unapply[T](f: Future[T]): Option[Try[T]] = f.value
}
}
}
Loading