DelayedPromise<T> Class
Similar to a normal Promise, a DelayedPromise represents the eventual completion (or failure) and resulting value of an asynchronous operation that has not yet started.
The asynchronous operation behind a DelayedPromise will start when any of the following occurs:
- The DelayedPromise is
await
ed. - A callback is attached via
.then()
or.catch(() => { })
. - The asynchronous operation is explicitly started via
.start()
Just as normal Promises will never return to their pending state once fulfilled or rejected, a DelayedPromise will never re-execute its asynchronous operation more than once.
Ultimately, a DelayedPromise is nothing more than some syntactic sugar that allows you to represent an (asynchronously) lazily-loaded value as an instance property instead of a method. You could also accomplish something similar by defining an async function as a property getter. However, since a property defined as a DelayedPromise will not start simply by being accessed, additional (non-lazily-loaded) "nested" properties can be added.
Implements
- Promise<T>
Methods
Name | Description | |
---|---|---|
constructor<T>(startCallback: () => Promise<T>): DelayedPromise<T> | Constructs a DelayedPromise object. | |
catch<TResult>(onrejected?: "null" | (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult> | Attaches a callback for only the rejection of the Promise. | |
finally(onFinally?: "null" | () => void): Promise<T> | Attaches a callback for only the finally clause of the Promise. | |
then<TResult1, TResult2>(onfulfilled?: "null" | (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: "null" | (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2> | Attaches callbacks for the resolution and/or rejection of the Promise. |
Properties
Name | Type | Description | |
---|---|---|---|
start | () => Promise<T> | Explicitly starts the asynchronous operation behind this DelayedPromise (if it hasn't started already). | |
[toStringTag] Readonly | "Promise" |
Defined in
Last Updated: 17 December, 2024