diff options
author | phaller <hallerp@gmail.com> | 2012-10-31 16:45:42 +0100 |
---|---|---|
committer | phaller <hallerp@gmail.com> | 2012-11-02 11:09:44 +0100 |
commit | f22998d343c01951254fc2020731986fb3219ff0 (patch) | |
tree | b5ae469b65156d3f4d3453dac213bfe6499cb985 /test/pending/run/fallback0/fallback0.scala | |
parent | c15af267fc7ed5dc7ef40428d738dd5679606f66 (diff) | |
download | scala-async-f22998d343c01951254fc2020731986fb3219ff0.tar.gz scala-async-f22998d343c01951254fc2020731986fb3219ff0.tar.bz2 scala-async-f22998d343c01951254fc2020731986fb3219ff0.zip |
Fix for #1861: Add fall-back to CPS for all unsupported uses of await
Diffstat (limited to 'test/pending/run/fallback0/fallback0.scala')
-rw-r--r-- | test/pending/run/fallback0/fallback0.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/pending/run/fallback0/fallback0.scala b/test/pending/run/fallback0/fallback0.scala new file mode 100644 index 0000000..75b0739 --- /dev/null +++ b/test/pending/run/fallback0/fallback0.scala @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com> + */ + +import language.{ reflectiveCalls, postfixOps } +import scala.concurrent.{ Future, ExecutionContext, future, Await } +import scala.concurrent.duration._ +import scala.async.Async.{ async, await, awaitCps } + +object Test extends App { + + Fallback0Spec.check() + +} + +class TestFallback0Class { + import ExecutionContext.Implicits.global + + def m1(x: Int): Future[Int] = future { + Thread.sleep(1000) + x + 2 + } + + def m2(y: Int): Future[Int] = async { + val f = m1(y) + var z = 0 + val res = await(f) + 5 + if (res > 0) { + z = 2 + } else { + z = 4 + } + z + } +} + + +object Fallback0Spec extends MinimalScalaTest { + + "An async method" should { + "support await in a simple if-else expression" in { + val o = new TestFallback0Class + val fut = o.m2(10) + val res = Await.result(fut, 2 seconds) + res mustBe(2) + } + } + +} |