diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-24 14:31:59 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-24 14:31:59 -0700 |
commit | 9f62900145029786457f27c1fe3083cde5d83fe2 (patch) | |
tree | 23a98110e11194b232f619f66472ed0acabbda17 /test/files/run/future-flatmap-exec-count.scala | |
parent | f0ca5aec4c575fe297adcd3e2b16018fff4a0639 (diff) | |
parent | 96a70e31f34be3eb1f3396ebbc74845659ea7e15 (diff) | |
download | scala-9f62900145029786457f27c1fe3083cde5d83fe2.tar.gz scala-9f62900145029786457f27c1fe3083cde5d83fe2.tar.bz2 scala-9f62900145029786457f27c1fe3083cde5d83fe2.zip |
Merge pull request #2983 from retronym/merge/2.10.3-to-2.10.x
Merge/2.10.3 to 2.10.x
Diffstat (limited to 'test/files/run/future-flatmap-exec-count.scala')
-rw-r--r-- | test/files/run/future-flatmap-exec-count.scala | 61 |
1 files changed, 61 insertions, 0 deletions
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 = ??? + } + } + } +} |