com.thoughtworks.zerocost.continuation
Parallel-tagged type of UnitContinuation that needs to be executed in parallel when using an cats.Applicative instance
Given two ParallelContinuations, each of them modifies a var,
var
import com.thoughtworks.zerocost.parallel._ import com.thoughtworks.zerocost.continuation._ 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,
import cats.syntax.all._ val result: ParallelContinuation[Unit] = (pc0, pc1).mapN{ (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
val Parallel(contResult) = result contResult.map { _: Unit => count0 should be(1) count1 should be(1) }.toScalaFuture
Given two ParallelContinuations that contain immediate values,
import com.thoughtworks.zerocost.parallel._ import com.thoughtworks.zerocost.continuation._ val pc0: ParallelContinuation[Int] = Parallel(Continuation.pure[Unit, Int](40)) val pc1: ParallelContinuation[Int] = Parallel(Continuation.pure[Unit, Int](2))
import cats.syntax.all._ val result: ParallelContinuation[Int] = (pc0, pc1).mapN(_ + _)
then the result should be a ParallelContinuation as well, and it is able to convert to a normal Continuation
val Parallel(contResult) = result contResult.map { _ should be(42) }.toScalaFuture
Parallel-tagged type of UnitContinuation that needs to be executed in parallel when using an cats.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 Continuation