resolver
Creates a new resolver.
Optionally accepts a value to which the promise will resolve when resolve is called without arguments. Note that the value will be discarded if resolve is called with an argument.
Type Parameters
T
TParameters
value
value?: TAn optional default to resolve to when calling resolve
Return Type
Resolver
A resolver wraps a promise so that it can be resolved by an outside event. It is a container for two things:
- a promise which you can
await - a function
resolvewhich you can call
Once you call resolve, the contained promise will resolve.
The status flag is indicates if resolve has been called or not.
Properties
promise
promise: Promise<T>;The promise which can be resolved by calling resolve
value
value?: T;Value of the promise, if is it resolved, and undefined otherwise
Methods
resolve
resolve(t?: T): void;
Resolves the promise of this resolver.
Does nothing if called repeatedly.
isResolved
isResolved(): this is { value: T };
A flag indicating whether resolve has been called, i.e. whether the promise has been resolved. Returns false until resolve is called, and returns true afterwards.