From 10f3c8db6163ebe3196173c1d87e69c1fb6a3a65 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 7 Nov 2013 15:27:40 +0100 Subject: Minimize the public API - Remove the CPS fallback version of async. That was not intended to be part of 1.0. - Lookup the await method beside the macro, rather than requiring all calls to go to AsyncBase.await. - Create a minimal version of Async that just contains await/async and delegates to the macro implementation in internal._ - Add scaladoc. --- pending/run/fallback0/fallback0-manual.scala | 71 ---------------------------- pending/run/fallback0/fallback0.scala | 48 ------------------- 2 files changed, 119 deletions(-) delete mode 100644 pending/run/fallback0/fallback0-manual.scala delete mode 100644 pending/run/fallback0/fallback0.scala (limited to 'pending') diff --git a/pending/run/fallback0/fallback0-manual.scala b/pending/run/fallback0/fallback0-manual.scala deleted file mode 100644 index 9bc570d..0000000 --- a/pending/run/fallback0/fallback0-manual.scala +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (C) 2012 Typesafe Inc. - */ - -import language.{ reflectiveCalls, postfixOps } -import scala.concurrent.{ Future, ExecutionContext, future, Await, Promise } -import scala.concurrent.duration._ -import scala.async.EndTaskException -import scala.async.Async.{ async, await, awaitCps } -import scala.util.continuations.reset - -object TestManual extends App { - - Fallback0ManualSpec.check() - -} - -class TestFallback0ManualClass { - import ExecutionContext.Implicits.global - - def m1(x: Int): Future[Int] = future { - x + 2 - } - - def m2(y: Int): Future[Int] = { - val p = Promise[Int]() - future { reset { - val f = m1(y) - var z = 0 - val res = awaitCps(f, p) + 5 - if (res > 0) { - z = 2 - } else { - z = 4 - } - z - } } - p.future - } - - /* that isn't even supported by current CPS plugin - def m3(y: Int): Future[Int] = { - val p = Promise[Int]() - future { reset { - val f = m1(y) - var z = 0 - val res: Option[Int] = Some(5) - res match { - case None => z = 4 - case Some(a) => z = awaitCps(f, p) - 10 - } - z - } } - p.future - } - */ -} - - -object Fallback0ManualSpec extends MinimalScalaTest { - - "An async method" should { - "support await in a simple if-else expression" in { - val o = new TestFallback0ManualClass - val fut = o.m2(10) - val res = Await.result(fut, 2 seconds) - res mustBe(2) - } - } - -} diff --git a/pending/run/fallback0/fallback0.scala b/pending/run/fallback0/fallback0.scala deleted file mode 100644 index fdb5568..0000000 --- a/pending/run/fallback0/fallback0.scala +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (C) 2012 Typesafe Inc. - */ - -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 { - 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) - } - } - -} -- cgit v1.2.3