I think that Promise.resolveand new Promise(resolve)interchangeably.
Consider this:
a.
new RSVP.Promise(function (resolve, reject) {
resolve();
}).then(function () {
return new RSVP.Promise(function (resolve) {
resolve("HI")
});
}).then(function (result) {
console.log(result);
});
IN.
new RSVP.Promise(function (resolve, reject) {
resolve();
}).then(function () {
return RSVP.resolve("HI");
}).then(function (result) {
console.log(result);
});
Both print "HI," as I expected.
Therefore, I think that if I do not need to βrejectβ anything. I just can write RSVP.resolve();for simplicity.
But consider this example:
new RSVP.Promise(function (resolve, reject) {
resolve();
}).then(function () {
return new RSVP.Promise(function (resolve, reject) {
setTimeout(function () {
resolve("HI")
}, 3000);
});
}).then(function (result) {
console.log(result);
});
How to use RSVP.resolve();for replacement? I tried for example:
new RSVP.Promise(function (resolve, reject) {
resolve();
}).then(function () {
return setTimeout(function () {
return new RSVP.resolve("HI");
}, 3000);
}).then(function (result) {
console.log(result);
});
Prints something else instead of "HI". So you can use RSVP.resolve (); Here? Are these two interchangeable?
source
share