eve.rt.future
Futures and promises for asynchronous value propagation.
A Future represents a value that may not yet be available, while a Promise is the producer side that completes the future with a value or an error. Together they provide a mechanism for asynchronous communication between different parts of the runtime.
Copyright
Types 5
Error thrown when attempting to retrieve a value from a future that was completed with an error.
this(string msg, string file = __FILE__, size_t line = __LINE__)Construct a FutureError with the given message.The state of a future's completion.
Policy controlling when completion callbacks execute.
When a Promise is created with an EventLoop, the policy determines how then()/onError()/onCancel() callbacks are delivered:
INLINE— callbacks execute immediately on the threadcalling
resolve()/reject()/cancel(). This is the default and matches the historical behaviour.DEFERRED— callbacks are queued viaEventLoop.defer()and execute on the next loop iteration. This prevents reentrancy and guarantees callbacks run on the loop thread.
DEFERRED requires an EventLoop. If no loop is available, callbacks execute inline regardless of the policy.
A future represents a value that will be available at some point.
Futures are the read-only consumer side of the future/promise pair. They allow checking whether a value is available and retrieving it once the corresponding promise has been completed.
Parameters
T | The type of value this future will hold. |
bool isCompleted() const @trusted nothrow @nogcCheck whether the future has been completed (resolved or rejected).Future!T then(void delegate(T) @safe callback) ref @trusted returnRegister a callback to be invoked when the future is resolved.Future!T onError(void delegate(string) @safe callback) ref @trusted returnRegister a callback to be invoked when the future is rejected.Future!T onCancel(void delegate() @safe callback) ref @trusted returnRegister a callback to be invoked when the future is cancelled.Future!U map(U)(U delegate(T) @safe fn) @trustedTransform the future's value with a mapping function, returning a new future that resolves with the mapped result.Future!T withCancel(CancelToken token) @trustedAttach an external cancellation token to this future.A promise is the producer side of a future/promise pair.
The promise holder can complete the associated future by either resolving it with a value or rejecting it with an error.
Parameters
T | The type of value this promise will produce. |
Functions 11
Promise!T promiseWithLoop(T)(EventLoop * loop, CompletionPolicy policy = CompletionPolicy.DEFERRED) @trustedCreate a promise/future pair with EventLoop integration.Future!T rejected(T)(string errorMsg) @safeCreate an already-rejected future with the given error.Future!T any(T)(Promise!T[] promises) @trustedResolve with the first successfully resolved future, or reject if all fail.