type

Future

src @Js
abstract const class Future : Obj

Future represents the result of an asynchronous computation.

See Actors

constructors

make

Subclass constructor

methods

cancel

Cancel this computation if it has not begun processing.

complete

Complete the future successfully with given value.

completeErr

Complete the future with a failure condition using given exception.

get

Block current thread until result is ready.

makeCompletable

Construct a completable future instance in the pending state.

status

Current state of asynchronous computation

waitFor

Block until this future transitions to a completed state (ok, err, or canceled).

waitForAll

Block on a list of futures until they all transition to a completed state.

Slot Details

cancel

src abstract Void cancel()

Cancel this computation if it has not begun processing. No guarantee is made that the computation will be cancelled.

complete

src abstract This complete(Obj? val)

Complete the future successfully with given value. Raise an exception if value is not immutable or the future is already complete (ignore this call if cancelled). Raise UnsupportedErr if this future is not completable. Return this. This method is subject to change.

completeErr

src abstract This completeErr(Err err)

Complete the future with a failure condition using given exception. Raise an exception if the future is already complete (ignore this call if cancelled). Return this. Raise UnsupportedErr if this future is not completable. This method is subject to change.

get

src abstract Obj? get(Duration? timeout := null)

Block current thread until result is ready. If timeout occurs then TimeoutErr is raised. A null timeout blocks forever. If an exception was raised by the asynchronous computation, then it is raised to the caller of this method.

make

src new make()

Subclass constructor

makeCompletable

src static Future makeCompletable()

Construct a completable future instance in the pending state. This method is subject to change.

status

src abstract FutureStatus status()

Current state of asynchronous computation

waitFor

src abstract This waitFor(Duration? timeout := null)

Block until this future transitions to a completed state (ok, err, or canceled). If timeout is null then block forever, otherwise raise a TimeoutErr if timeout elapses. Return this.

waitForAll

src static Void waitForAll(Future[] futures, Duration? timeout := null)

Block on a list of futures until they all transition to a completed state. If timeout is null block forever, otherwise raise TimeoutErr if any one of the futures does not complete before the timeout elapses.