From ffd7b9649cde61553f16c25f64c3072ecfa6c713 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Tue, 26 Feb 2013 01:16:40 +0100 Subject: 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 --- src/test/scala/scala/async/run/cps/CPSSpec.scala | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/scala/scala/async/run/cps/CPSSpec.scala (limited to 'src/test/scala') 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. + */ + +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") + } + +} -- cgit v1.2.3