Promise : Object
then()method to hook up a callback that will be called when the result of the asynchronous operation is ready. ECMAScript 2017 introduced
async function()s which return Promises and the
awaitkeyword which can simplify Promise based code.
Creates a new Promise. The Promise constructor calls
executer immediately with the two functions
executor should begin the asynchronous operation. When the operation is complete, call the
resolve function with the result. If there is an error during the operation, call
reject with the error information.
onReject to be called if the promise had an error (ie, the
executer function called
reject() or a method in the promise chain threw an error).
error is the value passed to
reject. This is a shorthand for calling
then(undefined, onReject). See also the window unhandledrejecton event.
onFinally to be called when the promise has been either resolved or rejected.
onResolve (if provided) to be called when the promise has been resolved.
value is the object passed to the
onReject (if provided) to be called when the promise has been rejected or an exception was thrown in the
error is the object passed to the
The return value from
onReject) can either be a normal Object or a Promise. If the return value from
onResolve is a normal Object, the Promise returned by
then() will be resolved with that Object. If the return value from
onResolve is a Promise,
then() will wait for that Promise to be resolved.
then() will resolve the Promise it returned with the same value.
Creates a new Promise that will be resolved when all of
promises are resolved or rejected. The result of the promise is an Array containing objects with a
status property (containing either
'rejected') and either a
value property (for fulfilled promises) or
reason property (for rejected promises). See also all().
Returns a new Promise that is in the rejected state with
error as the rejected error. Useful for passing values to APIs that expect promises.