AvailLazyFuture

class AvailLazyFuture<T>(val runtime: AvailRuntime, val priority: Int = compilerPriority, val computation: ((T) -> Unit) -> Unit)

An implementation of a lazy future, using the runtime's execution pool. If the value is never requested, it never not run the computation. Otherwise, the first invocation of withValue causes the computation to run in a task (when it's safe to run interpreters).

When the computation completes, any actions queued in the waiters list by withValue will run, inside their own tasks.

Constructors

Link copied to clipboard
constructor(runtime: AvailRuntime, priority: Int = compilerPriority, computation: ((T) -> Unit) -> Unit)

Create an AvailLazyFuture which runs the computation, once, if requested.

Properties

Link copied to clipboard
val computation: ((T) -> Unit) -> Unit

The function to evaluate if anyone requests the lazy future's value. The function takes another function, supplied by the lazy future's internals, responsible for running any waiting actions.

Link copied to clipboard

The priority at which to run tasks.

Link copied to clipboard

The AvailRuntime responsible for executing the computation and actions.

Functions

Link copied to clipboard
fun withValue(action: (T) -> Unit): Any

Ensure the given action will run with the result of the computation. If this is the first request for this future, launch a task to run the computation, evaluating all waiters when complete. If the value has not yet been computed, add the action to the waiters. If the value has been computed, just run the action. Note that all evaluation takes place while interpreters may run.