UnsafePromise
- class Util.UnsafePromise()
This represents a
Promise
that has its promised return value immediately available. The immediate value is unsafe to use (safety depends on specific use cases) until thisUnsafePromise
becomes marked as ready.The primary use case of this would be to synchronously return a reference to an object that needs to wait for an
init(): Promise<void>
function to complete.
Properties
Properties
- UnsafePromise.[toStringTag]
- Type
string
- UnsafePromise.isReady
- Type
boolean
This value becomes
true
oncethis.readyPromise
resolves. Ifthis.readyPromise
rejects, this value never becomestrue
.
- UnsafePromise.readyPromise
- Type
Promise <void>
This promise resolves once
this.unsafeValue
is safe to access.
- UnsafePromise.unsafeValue
- Type
T
An unsafe synchronous reference to the value returned through this promise’s
then()
callback.
Methods
catch
- UnsafePromise.catch([onrejected])
- Arguments
onrejected (
null | function()
) – optional The callback to execute when the Promise is rejected.
Attaches a callback for only the rejection of the Promise.
- Returns
A Promise for the completion of the callback.
- Return type
Promise <T | TResult>
- UnsafePromise.onrejected(reason)
- Arguments
reason (
any()
) – None
- Return type
TResult | PromiseLike <TResult>
finally
- UnsafePromise.finally([onfinally])
- Arguments
onfinally (
null | function()
) – optional The callback to execute when the Promise is settled (fulfilled or rejected).
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
- Returns
A Promise for the completion of the callback.
- Return type
Promise <T>
- UnsafePromise.onfinally()
- Return type
void
then
- UnsafePromise.then([onfulfilled[, onrejected]])
- Arguments
onfulfilled (
null | function()
) – optional The callback to execute when the Promise is resolved.onrejected (
null | function()
) – optional The callback to execute when the Promise is rejected.
Attaches callbacks for the resolution and/or rejection of the Promise.
- Returns
A Promise for the completion of which ever callback is executed.
- Return type
Promise <TResult1 | TResult2>
- UnsafePromise.onfulfilled(value)
- Arguments
value (
T()
) – None
- Return type
TResult1 | PromiseLike <TResult1>
- Util.onrejected(reason)
- Arguments
reason (
any()
) – None
- Return type
TResult2 | PromiseLike <TResult2>