Permalink
Browse files

Unbreaking tryComplete + Future.apply since resolver must be use both…

… for boxing of callback and for execution
  • Loading branch information...
viktorklang committed Apr 16, 2012
1 parent 8ef8d3e commit 813f7ec8d40e188fba545ef9831acabad7a40dbb
@@ -50,7 +50,7 @@ private[concurrent] object Future {
def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = {
val promise = new Promise.DefaultPromise[T]()
executor.execute(new Runnable {
def run = promise complete { try Right(body) catch { case NonFatal(e) => Left(e) } }
def run = promise complete { try Right(body) catch { case e => Left(e) } }
})
promise.future
}
@@ -89,6 +89,7 @@ object Promise {
protected final def getState: AnyRef = updater.get(this)
def tryComplete(value: Either[Throwable, T]): Boolean = {
val resolved = resolveEither(value)
(try {
@tailrec
def tryComplete(v: Either[Throwable, T]): List[Either[Throwable, T] => Unit] = {
@@ -99,13 +100,13 @@ object Promise {
case _ => null
}
}
tryComplete(resolveEither(value))
tryComplete(resolved)
} finally {
synchronized { notifyAll() } //Notify any evil blockers
}) match {
case null => false
case cs if cs.isEmpty => true
case cs => Future.dispatchFuture(executor, () => cs.foreach(f => notifyCompleted(f, value))); true
case cs => Future.dispatchFuture(executor, () => cs.foreach(f => notifyCompleted(f, resolved))); true
}
}

0 comments on commit 813f7ec

Please sign in to comment.