Are Promise.resolve And New Promise(resolve) Interchangeable
I think Promise.resolve and new Promise(resolve) are interchangeable. Consider this: A. new RSVP.Promise(function (resolve, reject) { resolve(); }).then(function () { retur
Solution 1:
First and foremost
I think Promise.resolve and new Promise(resolve) are interchangeable.
Nope. Promise.resolve
will create a promise which is already resolved, whereas new Promise(resolve)
creates a promise which is neither resolved nor rejected.
In the last example,
return setTimeout(function () {
return new RSVP.resolve("HI");
}, 3000);
means that, you are returning the result of setTimeout
function, not a promise object. So, the current then
handler will return a resolved promise with the result of setTimeout
. That is why you are seeing a weird object.
In your particular case, you want to introduce a delay before resolving the promise. It is not possible with Promise.resolve
. The penultimate method you have shown in the question, is the way to go.
Post a Comment for "Are Promise.resolve And New Promise(resolve) Interchangeable"