Permalink
Browse files

Merge pull request #2502 from viktorklang/wip-SI7383-EC-prepare-in-Fu…

…ture-apply-2.10-√

SI-7383 - call ExecutionContext.prepare in Future.apply
  • Loading branch information...
adriaanm committed May 15, 2013
2 parents 76b8724 + b32d294 commit 487584caa97d0905df06e32c292c00fcd82a2fa3
Showing with 20 additions and 1 deletion.
  1. +1 −1 src/library/scala/concurrent/impl/Future.scala
  2. +19 −0 test/files/jvm/future-spec/FutureTests.scala
@@ -28,7 +28,7 @@ private[concurrent] object Future {
def apply[T](body: =>T)(implicit executor: ExecutionContext): scala.concurrent.Future[T] = {
val runnable = new PromiseCompletingRunnable(body)
- executor.execute(runnable)
+ executor.prepare.execute(runnable)
runnable.promise.future
}
}
@@ -71,6 +71,25 @@ object FutureTests extends MinimalScalaTest {
}
}
+ "The Future companion object" should {
+ "call ExecutionContext.prepare on apply" in {
+ val p = Promise[Boolean]()
+ val ec = new ExecutionContext {
+ val delegate = ExecutionContext.global
+ override def prepare(): ExecutionContext = {
+ p.success(true)
+ delegate.prepare
+ }
+ override def execute(r: Runnable) = delegate.execute(r)
+ override def reportFailure(t: Throwable): Unit = delegate.reportFailure(t)
+ }
+
+ val f = Future("foo")(ec)
+ Await.result(f, defaultTimeout) mustBe ("foo")
+ Await.result(p.future, defaultTimeout) mustBe (true)
+ }
+ }
+
"The default ExecutionContext" should {
"report uncaught exceptions" in {
val p = Promise[Throwable]()

0 comments on commit 487584c

Please sign in to comment.