diff options
author | Philipp Haller <hallerp@gmail.com> | 2013-02-26 01:16:40 +0100 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2013-04-12 18:53:28 +0200 |
commit | ffd7b9649cde61553f16c25f64c3072ecfa6c713 (patch) | |
tree | 54f458e8e9061c8537a0972ca827a56cc0ce9548 /src/test/scala/scala/async | |
parent | 1a8b72a0d1ee16ddcff637df57c2b22e2976b853 (diff) | |
download | scala-async-ffd7b9649cde61553f16c25f64c3072ecfa6c713.tar.gz scala-async-ffd7b9649cde61553f16c25f64c3072ecfa6c713.tar.bz2 scala-async-ffd7b9649cde61553f16c25f64c3072ecfa6c713.zip |
Remove CPS dependency from default async implementation
- move all CPS-related code to `continuations` sub package
- fix CPS-based async implementation
- enable testing of CPS-based async implementation
Diffstat (limited to 'src/test/scala/scala/async')
-rw-r--r-- | src/test/scala/scala/async/run/cps/CPSSpec.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/run/cps/CPSSpec.scala b/src/test/scala/scala/async/run/cps/CPSSpec.scala new file mode 100644 index 0000000..b56c6ad --- /dev/null +++ b/src/test/scala/scala/async/run/cps/CPSSpec.scala @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com> + */ + +package scala.async +package run +package cps + +import scala.concurrent.{Future, Promise, ExecutionContext, future, Await} +import scala.concurrent.duration._ +import scala.async.continuations.CPSBasedAsync._ +import scala.util.continuations._ + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class CPSSpec { + + import ExecutionContext.Implicits.global + + def m1(y: Int): Future[Int] = async { + val f = future { y + 2 } + val f2 = future { y + 3 } + val x1 = await(f) + val x2 = await(f2) + x1 + x2 + } + + def m2(y: Int): Future[Int] = async { + val f = future { y + 2 } + val res = await(f) + if (y > 0) res + 2 + else res - 2 + } + + @Test + def testCPSFallback() { + val fut1 = m1(10) + val res1 = Await.result(fut1, 2.seconds) + assert(res1 == 25, s"expected 25, got $res1") + + val fut2 = m2(10) + val res2 = Await.result(fut2, 2.seconds) + assert(res2 == 14, s"expected 14, got $res2") + } + +} |