aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
diff options
context:
space:
mode:
authorphaller <hallerp@gmail.com>2012-11-26 17:28:51 +0100
committerphaller <hallerp@gmail.com>2012-11-26 23:26:16 +0100
commit9ea2cc44e98c110843780aef09c7d1a695458be3 (patch)
tree3b7eb7ad3c8e6b983675a020d1f4fe7edb72bdca /src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
parent3fd51865dfcb6121f84145f4504abd0f80bf6cca (diff)
downloadscala-async-9ea2cc44e98c110843780aef09c7d1a695458be3.tar.gz
scala-async-9ea2cc44e98c110843780aef09c7d1a695458be3.tar.bz2
scala-async-9ea2cc44e98c110843780aef09c7d1a695458be3.zip
Fix #42 - Futures created by async are not properly completed with exceptions
This augments the on-complete handler for an async state with await as follows: if (tr.isFailure) result$async.complete(tr.asInstanceOf[Try[T]]) else { <resultName> = tr.get.asInstanceOf[<resultType>] <nextState> <mkResumeApply> }
Diffstat (limited to 'src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala')
-rw-r--r--src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
new file mode 100644
index 0000000..6f9e4ec
--- /dev/null
+++ b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
+ */
+
+package scala.async
+package run
+package exceptions
+
+import scala.async.Async.{async, await}
+
+import scala.concurrent.{future, ExecutionContext, Await}
+import ExecutionContext.Implicits._
+import scala.concurrent.duration._
+import scala.reflect.ClassTag
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class ExceptionsSpec {
+
+ @Test
+ def `complete future with exception`() {
+ val future0 = future[Any] {
+ "five!".length
+ }
+
+ val future2 = async {
+ val a = await(future0.mapTo[Int]) // result: 5
+ val b = await((future { (a * 2).toString }).mapTo[Int]) // result: 10
+ val c = await(future { (7 * 2).toString }) // result: "14"
+ b + "-" + c
+ }
+
+ intercept[ClassCastException] { Await.result(future2, 5.seconds) }
+ }
+
+}