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 awaited.
  • 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.


  • Promise<T>


Name Description
constructor(startCallback: () => Promise<T>): DelayedPromise Constructs a DelayedPromise object.  
catch<TResult>(onrejected?: (reason: any) => TResult | PromiseLike<TResult> | null): Promise<T | TResult> Attaches a callback for only the rejection of the Promise.  
finally(onFinally?: () => void | null): Promise<T> Attaches a callback for only the finally clause of the Promise.  
then<TResult1, TResult2>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1> | null, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2> | null): Promise<TResult1 | TResult2> Attaches callbacks for the resolution and/or rejection of the Promise.  


Name Type Description
start () => Promise<T> Explicitly starts the asynchronous operation behind this DelayedPromise (if it hasn't started already).  
[Symbol.toStringTag] "Promise" = "Promise"    

Defined in

Last Updated: 01 December, 2021