diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-24 19:00:28 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-24 19:00:28 +0200 |
commit | 96a70e31f34be3eb1f3396ebbc74845659ea7e15 (patch) | |
tree | 23a98110e11194b232f619f66472ed0acabbda17 /test | |
parent | f0ca5aec4c575fe297adcd3e2b16018fff4a0639 (diff) | |
parent | e2fec6b28dfd73482945ffab85d9b582d0cb9f17 (diff) | |
download | scala-96a70e31f34be3eb1f3396ebbc74845659ea7e15.tar.gz scala-96a70e31f34be3eb1f3396ebbc74845659ea7e15.tar.bz2 scala-96a70e31f34be3eb1f3396ebbc74845659ea7e15.zip |
Merge remote-tracking branch 'origin/2.10.3' into merge/2.10.3-to-2.10.x
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/future-flatmap-exec-count.check | 6 | ||||
-rw-r--r-- | test/files/run/future-flatmap-exec-count.scala | 61 |
2 files changed, 67 insertions, 0 deletions
diff --git a/test/files/run/future-flatmap-exec-count.check b/test/files/run/future-flatmap-exec-count.check new file mode 100644 index 0000000000..dd9dce64ed --- /dev/null +++ b/test/files/run/future-flatmap-exec-count.check @@ -0,0 +1,6 @@ +mapping +execute() +flatmapping +execute() +recovering +execute() diff --git a/test/files/run/future-flatmap-exec-count.scala b/test/files/run/future-flatmap-exec-count.scala new file mode 100644 index 0000000000..86c37be938 --- /dev/null +++ b/test/files/run/future-flatmap-exec-count.scala @@ -0,0 +1,61 @@ +import scala.concurrent._ +import java.util.concurrent.atomic.AtomicInteger + +object Test { + def main(args: Array[String]) { + test() + } + + def test() = { + def await(f: Future[Any]) = + Await.result(f, duration.Duration.Inf) + + val ec = new TestExecutionContext(ExecutionContext.Implicits.global) + + { + val p = Promise[Int]() + val fp = p.future + println("mapping") + val mapped = fp.map(x => x)(ec) + p.success(0) + await(mapped) + } + + { + println("flatmapping") + val p = Promise[Int]() + val fp = p.future + val flatMapped = fp.flatMap({ (x: Int) => + Future.successful(2 * x) + })(ec) + p.success(0) + await(flatMapped) + } + + { + println("recovering") + val recovered = Future.failed(new Throwable()).recoverWith { + case _ => Future.successful(2) + }(ec) + await(recovered) + } + } + + class TestExecutionContext(delegate: ExecutionContext) extends ExecutionContext { + def execute(runnable: Runnable): Unit = ??? + + def reportFailure(t: Throwable): Unit = ??? + + override def prepare(): ExecutionContext = { + val preparedDelegate = delegate.prepare() + return new ExecutionContext { + def execute(runnable: Runnable): Unit = { + println("execute()") + preparedDelegate.execute(runnable) + } + + def reportFailure(t: Throwable): Unit = ??? + } + } + } +} |