Class: ExternalPromise implements Promise
A promise that can be resolved / rejected externally.
Note:
- The class implements
Promise
and does not extend it. This means thatnew ExternalPromise() instanceof Promise
will be false. - The native Promise methods
then
,catch
andfinally
return the ordinary Promise instance that is stored internally, not the instance.
Initializes an external promise.
Returns Promise
- returns the native Promise.
Despite a common interface, ExternalPromise does not extend Promise for backward compatibility reasons. Obtaining the native Promise may be desirable when the Promise is to be exposed externally, i.e. as the return value of a method or a function. This is because instances of ExternalPromise will not pass p instanceof Promise
check.
Returns string
- 'pending' | 'resolved' | 'rejected'
value
unknown - the value to resolve the promise with.
Resolves the promise.
reason
unknown - the value to reject the promise with. An Error instance is recommended.
Rejects the promise.