Continuations

class Object
trait Matchable
class Any

Type members

Types

opaque type BoundaryLabel[T]

A marker for a given boundary. Use break or suspend to suspend the continuation up to the specified boundary. This value MUST NOT escape the boundary that created it.

A marker for a given boundary. Use break or suspend to suspend the continuation up to the specified boundary. This value MUST NOT escape the boundary that created it.

Value members

Concrete methods

inline def boundary[T](inline body: BoundaryLabel[T] ?=> T): T

Marks the given body as suspendable with a BoundaryLabel that suspend can refer to. Forwards the return value of body, or the return value of the suspend call, if it happens during the execution of f.

Marks the given body as suspendable with a BoundaryLabel that suspend can refer to. Forwards the return value of body, or the return value of the suspend call, if it happens during the execution of f.

Safety: the passed-in BoundaryLabel cannot be used outside of the scope of the body. Suspending to a BoundaryLabel not created by a boundary call higher on the same call stack is undefined behaviour.

inline def boundaryBodyFn[T]: ContinuationBodyPtr[T]

Transformed version of the boundary body, to be passed to cont_boundary. Takes:

Transformed version of the boundary body, to be passed to cont_boundary. Takes:

  • label: the boundary label
  • arg: The boundary body as BoundaryLabel ?=> Ptr[?] (the returned object, cast to a pointer)

Returns Ptr[?] / void*.

inline def break(using BoundaryLabel[Unit]): Nothing

Immediately return to the boundary.

Immediately return to the boundary.

inline def break[T](inline value: T)(using BoundaryLabel[T]): Nothing

Immediately return to the boundary, returning the given value.

Immediately return to the boundary, returning the given value.

inline def suspend[R, T](inline onSuspend: (R => T) => T)(using label: BoundaryLabel[T]): R

Suspends the current running stack up to the corresponding boundary into a continuation cont: R => T and passes it into f. The return value of f(cont) is returned to boundary.

Suspends the current running stack up to the corresponding boundary into a continuation cont: R => T and passes it into f. The return value of f(cont) is returned to boundary.

Same as suspendCont, but hides the fact that the passed in function is a continuation.

inline def suspend[T](inline onSuspend: (() => T) => T)(using label: BoundaryLabel[T]): Unit

Same as suspend where the continuation expects no parameters.

Same as suspend where the continuation expects no parameters.

inline def suspendFn[R, T]: SuspendFnPtr[R, T]

Transformed version of the suspend lambda, to be passed to cont_suspend. Takes:

Transformed version of the suspend lambda, to be passed to cont_suspend. Takes:

  • continuation: the reified continuation
  • onSuspend: The suspend lambda as Continuation => Ptr[?] (the returned object, cast to a pointer)

Returns Ptr[?] / void*.