Type

com.thoughtworks.zerocost.continuation

ParallelContinuation

Related Doc: package continuation

Permalink

type ParallelContinuation[A] = Parallel[UnitContinuation, A]

Parallel-tagged type of UnitContinuation that needs to be executed in parallel when using an cats.Applicative instance

Source
continuation.scala
Examples:
  1. Given two ParallelContinuations, each of them modifies a 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.

    val Parallel(contResult) = result
    contResult.map { _: Unit =>
      count0 should be(1)
      count1 should be(1)
    }.toScalaFuture
  2. ,
  3. 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))

    when map them together,

    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
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getClass(): Class[_]

    Permalink
    Definition Classes
    Any

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. def hashCode(): Int

    Permalink
    Definition Classes
    Any
  7. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  8. def toString(): String

    Permalink
    Definition Classes
    Any

Ungrouped