diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-20 14:02:44 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-21 09:04:15 +0200 |
commit | 7f4b44b612abdc62fba9810194cee17c7d0de37e (patch) | |
tree | f4b3268f6cb3d8246f8520571570ee87c022ab14 /src/library | |
parent | e176a1005186f5d6da8ed5a79820d12ca7280e3b (diff) | |
download | scala-7f4b44b612abdc62fba9810194cee17c7d0de37e.tar.gz scala-7f4b44b612abdc62fba9810194cee17c7d0de37e.tar.bz2 scala-7f4b44b612abdc62fba9810194cee17c7d0de37e.zip |
SI-7861 Don't execute internal callbacks on the user Executor
Callbacks internal to the implementation of Futures should be
executed with the `InternalCallbackExecutor`, rather than the
user supplied `Executor`.
In a refactoring da54f34a6, `recoverWith` and `flatMap` no longer
played by these rules. This was noticed by a persnickety test in
Play.
Before this patch, the enclosed test outputs:
% scala-hash v2.10.3-RC2 test/files/run/future-flatmap-exec-count.scala
mapping
execute()
flatmapping
execute()
execute()
recovering
execute()
execute()
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/concurrent/Future.scala | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index caf91fbb0f..39946e4472 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -96,11 +96,8 @@ trait Future[+T] extends Awaitable[T] { // of the Future trait. Note that this will // (modulo bugs) _never_ execute a callback // other than those below in this same file. - // As a nice side benefit, having this implicit - // here forces an ambiguity in those methods - // that also have an executor parameter, which - // keeps us from accidentally forgetting to use - // the executor parameter. + // + // See the documentation on `InternalCallbackExecutor` for more details. private def internalExecutor = Future.InternalCallbackExecutor /* Callbacks */ @@ -254,7 +251,7 @@ trait Future[+T] extends Awaitable[T] { case Success(v) => try f(v) match { // If possible, link DefaultPromises to avoid space leaks case dp: DefaultPromise[_] => dp.asInstanceOf[DefaultPromise[S]].linkRootOf(p) - case fut => fut onComplete p.complete + case fut => fut.onComplete(p.complete)(internalExecutor) } catch { case NonFatal(t) => p failure t } } p.future @@ -344,7 +341,7 @@ trait Future[+T] extends Awaitable[T] { def recoverWith[U >: T](pf: PartialFunction[Throwable, Future[U]])(implicit executor: ExecutionContext): Future[U] = { val p = Promise[U]() onComplete { - case Failure(t) => try pf.applyOrElse(t, (_: Throwable) => this) onComplete p.complete catch { case NonFatal(t) => p failure t } + case Failure(t) => try pf.applyOrElse(t, (_: Throwable) => this).onComplete(p.complete)(internalExecutor) catch { case NonFatal(t) => p failure t } case other => p complete other } p.future |