Permalink
Browse files

Removing some verbosity in Promise.tryComplete

  • Loading branch information...
viktorklang committed Apr 15, 2012
1 parent 768748b commit a5d1ac762836acb0e3b32375bac22a82cf25c4c7
Showing with 12 additions and 16 deletions.
  1. +12 −16 src/library/scala/concurrent/impl/Promise.scala
@@ -89,24 +89,20 @@ object Promise {
protected final def getState: AnyRef = updater.get(this)
def tryComplete(value: Either[Throwable, T]): Boolean = {
val callbacks: List[Either[Throwable, T] => Unit] = {
try {
@tailrec
def tryComplete(v: Either[Throwable, T]): List[Either[Throwable, T] => Unit] = {
getState match {
case raw: List[_] =>
val cur = raw.asInstanceOf[List[Either[Throwable, T] => Unit]]
if (updateState(cur, v)) cur else tryComplete(v)
case _ => null
}
(try {
@tailrec
def tryComplete(v: Either[Throwable, T]): List[Either[Throwable, T] => Unit] = {
getState match {
case raw: List[_] =>
val cur = raw.asInstanceOf[List[Either[Throwable, T] => Unit]]
if (updateState(cur, v)) cur else tryComplete(v)
case _ => null
}
tryComplete(resolveEither(value))
} finally {
synchronized { notifyAll() } //Notify any evil blockers
}
}
callbacks match {
tryComplete(resolveEither(value))
} 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

0 comments on commit a5d1ac7

Please sign in to comment.