Skip to content

Commit 487584c

Browse files
committed
Merge pull request scala#2502 from viktorklang/wip-SI7383-EC-prepare-in-Future-apply-2.10-√
SI-7383 - call ExecutionContext.prepare in Future.apply
2 parents 76b8724 + b32d294 commit 487584c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/library/scala/concurrent/impl/Future.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private[concurrent] object Future {
2828

2929
def apply[T](body: =>T)(implicit executor: ExecutionContext): scala.concurrent.Future[T] = {
3030
val runnable = new PromiseCompletingRunnable(body)
31-
executor.execute(runnable)
31+
executor.prepare.execute(runnable)
3232
runnable.promise.future
3333
}
3434
}

test/files/jvm/future-spec/FutureTests.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ object FutureTests extends MinimalScalaTest {
7171
}
7272
}
7373

74+
"The Future companion object" should {
75+
"call ExecutionContext.prepare on apply" in {
76+
val p = Promise[Boolean]()
77+
val ec = new ExecutionContext {
78+
val delegate = ExecutionContext.global
79+
override def prepare(): ExecutionContext = {
80+
p.success(true)
81+
delegate.prepare
82+
}
83+
override def execute(r: Runnable) = delegate.execute(r)
84+
override def reportFailure(t: Throwable): Unit = delegate.reportFailure(t)
85+
}
86+
87+
val f = Future("foo")(ec)
88+
Await.result(f, defaultTimeout) mustBe ("foo")
89+
Await.result(p.future, defaultTimeout) mustBe (true)
90+
}
91+
}
92+
7493
"The default ExecutionContext" should {
7594
"report uncaught exceptions" in {
7695
val p = Promise[Throwable]()

0 commit comments

Comments
 (0)