To create a promise to represent a single known value, use the following two methods.
The Promise.resolve()
method accepts a single argument.
It returns a promise in the fulfilled state.
No job scheduling occurs, and you need to add one or more fulfillment handlers to the promise to retrieve the value.
let promise = Promise.resolve(42); promise.then(function(value) { console.log(value); // 42 });//from w w w .ja v a 2s . c om
This code creates a fulfilled promise so the fulfillment handler receives 42 as value
.
If a rejection handler were added to this promise, the rejection handler would never be called because the promise will never be in the rejected state.