Permalink
Browse files

Fixed the stupid exception code. Every part of this code which looks

nice is proposed by Tiark. Many thanks!
  • Loading branch information...
danielkroeni committed Feb 17, 2012
1 parent 11b9549 commit 134d7d859b2f24f3204c241f729156de083ee487
Showing with 3 additions and 11 deletions.
  1. +3 −11 src/main/scala/async/Async.scala
@@ -37,17 +37,9 @@ object Async {
def await[A](block: => Future[A]): A@suspendable = {
val ec = localContext get()
- val ex = new AtomicReference[Throwable] // holds the exception if any
- val a = shift[A,Unit,Unit] { cont: (A => Unit) =>
- block onComplete {
- case Right(r) => ec.execute(cont(r))
- case Left(e) =>
- ex.set(e) // store exception
- ec.execute(cont(null.asInstanceOf[A])) //TODO solve appropriately
- }
+ val a = shift[Either[Throwable,A],Unit,Unit] { cont: (Either[Throwable,A] => Unit) =>
+ block onComplete { r => ec.execute(cont(r)) }
}
- // rethrow exception if any
- if(ex.get() != null) throw ex.get()
- a
+ a.fold(throw _, x => x)
}
}

0 comments on commit 134d7d8

Please sign in to comment.