The stack-safe and covariant version of scalaz.Cont.
The stack-safe and covariant version of scalaz.Cont.
The underlying type of this Continuation
is (A => Trampoline[R]) => Trampoline[R]
.
UnitContinuation if you want to use this Continuation
as an asynchronous task.
ContinuationOps for extension methods for this Continuation
.
Extension methods for Continuation
Parallel-tagged type of UnitContinuation that needs to be executed in parallel when using an scalaz.Applicative instance
Parallel-tagged type of UnitContinuation that needs to be executed in parallel when using an scalaz.Applicative instance
Given two ParallelContinuations,
each of them modifies a var
,
import com.thoughtworks.continuation._ import scalaz.Tags.Parallel import scalaz.syntax.all._ var count0 = 0 var count1 = 0 val pc0: ParallelContinuation[Unit] = Parallel(Continuation.delay { count0 += 1 }) val pc1: ParallelContinuation[Unit] = Parallel(Continuation.delay { count1 += 1 })
when map them together,
val result: ParallelContinuation[Unit] = (pc0 |@| pc1) { (u0: Unit, u1: Unit) => }
then the two vars have not been modified right now,
count0 should be(0) count1 should be(0)
when the result ParallelContinuation
get done,
then two vars should be modified only once for each.
Parallel.unwrap(result).map { _: Unit => count0 should be(1) count1 should be(1) }
Given two ParallelContinuations that contain immediate values,
import com.thoughtworks.continuation._ import scalaz.Tags.Parallel import scalaz.syntax.all._ val pc0: ParallelContinuation[Int] = Parallel(Continuation.now[Unit, Int](40)) val pc1: ParallelContinuation[Int] = Parallel(Continuation.now[Unit, Int](2))
when map them together,
val result: ParallelContinuation[Int] = (pc0 |@| pc1)(_ + _)
then the result should be a ParallelContinuation
as well,
and it is able to convert to a normal Continuation
Parallel.unwrap(result).map {
_ should be(42)
}
A Continuation whose response type is scala.Unit.
A Continuation whose response type is scala.Unit.
This UnitContinuation
type can be used as an asynchronous task.
This UnitContinuation
type does not support exception handling.
Future for asynchronous task that supports exception handling.
ParallelContinuation for parallel version of this UnitContinuation
.
UnitContinuationOps for extension methods for this UnitContinuationOps
.
Extension methods for UnitContinuation
The companion object for Continuation.
The name space that contains Continuation and utilities for
Continuation
.Author:
杨博 (Yang Bo)