diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-12-02 17:10:35 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-12-13 17:36:16 -0800 |
commit | 858a5d513779f4af6f12c0a530bdeceb7a7fd4d9 (patch) | |
tree | becda6df1363a92c1fcdf39643433ba101de4c10 /test/files/continuations-run/t5472.scala | |
parent | 7e74aa6b134bcaf158bd51aa7a63a4aaa8fee62e (diff) | |
download | scala-858a5d513779f4af6f12c0a530bdeceb7a7fd4d9.tar.gz scala-858a5d513779f4af6f12c0a530bdeceb7a7fd4d9.tar.bz2 scala-858a5d513779f4af6f12c0a530bdeceb7a7fd4d9.zip |
Modularize continuations plugin.
The continuations plugin and library will still ship with 2.11 (albeit unsupported).
They now reside at https://github.com/scala/scala-continuations.
Diffstat (limited to 'test/files/continuations-run/t5472.scala')
-rw-r--r-- | test/files/continuations-run/t5472.scala | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/test/files/continuations-run/t5472.scala b/test/files/continuations-run/t5472.scala deleted file mode 100644 index 060d267544..0000000000 --- a/test/files/continuations-run/t5472.scala +++ /dev/null @@ -1,91 +0,0 @@ -import scala.annotation._ -import scala.util.continuations._ -import java.util.concurrent.atomic._ - -@deprecated("Suppress warnings", since="2.11") -object Test { - def main(args: Array[String]) { - val map = Map("foo" -> 1, "bar" -> 2) - reset { - val mapped = - for { - (location, accessors) <- new ContinuationizedParallelIterable(map) - } yield { - shiftUnit0[Int, Unit](23) - } - println(mapped.toList) - } - } - -final class ContinuationizedParallelIterable[+A](protected val underline: Iterable[A]) { - def toList = underline.toList.sortBy(_.toString) - - final def filter(p: A => Boolean @suspendable): ContinuationizedParallelIterable[A] @suspendable = - shift( - new AtomicInteger(1) with ((ContinuationizedParallelIterable[A] => Unit) => Unit) { - private val results = new AtomicReference[List[A]](Nil) - - @tailrec - private def add(element: A) { - val old = results.get - if (!results.compareAndSet(old, element :: old)) { - add(element) - } - } - - override final def apply(continue: ContinuationizedParallelIterable[A] => Unit) { - for (element <- underline) { - super.incrementAndGet() - reset { - val pass = p(element) - if (pass) { - add(element) - } - if (super.decrementAndGet() == 0) { - continue(new ContinuationizedParallelIterable(results.get)) - } - } - } - if (super.decrementAndGet() == 0) { - continue(new ContinuationizedParallelIterable(results.get)) - } - } - }) - - final def foreach[U](f: A => U @suspendable): Unit @suspendable = - shift( - new AtomicInteger(1) with ((Unit => Unit) => Unit) { - override final def apply(continue: Unit => Unit) { - for (element <- underline) { - super.incrementAndGet() - reset { - f(element) - if (super.decrementAndGet() == 0) { - continue() - } - } - } - if (super.decrementAndGet() == 0) { - continue() - } - } - }) - - final def map[B: Manifest](f: A => B @suspendable): ContinuationizedParallelIterable[B] @suspendable = - shift( - new AtomicInteger(underline.size) with ((ContinuationizedParallelIterable[B] => Unit) => Unit) { - override final def apply(continue: ContinuationizedParallelIterable[B] => Unit) { - val results = new Array[B](super.get) - for ((element, i) <- underline.view.zipWithIndex) { - reset { - val result = f(element) - results(i) = result - if (super.decrementAndGet() == 0) { - continue(new ContinuationizedParallelIterable(results)) - } - } - } - } - }) -} -} |