com.thoughtworks.continuation
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,
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.
ParallelContinuation
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))
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) }
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
,when map them together,
then the two vars have not been modified right now,
when the result
ParallelContinuation
get done, then two vars should be modified only once for each.Given two ParallelContinuations that contain immediate values,
when map them together,
then the result should be a
ParallelContinuation
as well, and it is able to convert to a normal ContinuationParallel.unwrap(result).map { _ should be(42) }