Permalink
Browse files

SI-7383 - Call ExecutionContext.prepare in Future.apply to allow for …

…capturing local context like ThreadLocals and then re-establishing them prior to execution, as per intention of EC.prepare
  • Loading branch information...
viktorklang committed May 8, 2013
1 parent 5c77e01 commit b32d294e14615bea0c062dd61350f8ab6a05b8dc
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 b32d294

Please sign in to comment.