I think Promise.resolve
and new Promise(resolve)
are interchangeable.
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);
});
B.
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.
So I think if I don't need to "reject" anything. I can just 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 can I use RSVP.resolve();
to replace? 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);
});
This prints something else instead of "HI". So is it possible to use RSVP.resolve(); here? Are these two interchangeable?