I am new to Promise. I wrote two examples:
The first one is:
new RSVP.Promise(function (resolve, reject) {
setTimeout(function () {
resolve("HI")
}, 3000);
}).then(function (result) {
console.log(result);
});
This one will print out "HI" after 3 seconds as I expected. This is because "then" waits on it, and is only called when the promise settles.
The second one is:
new RSVP.Promise(function (resolve, reject) {
resolve();
}).then(function () {
return RSVP.Promise(function (resolve, reject) {
setTimeout(function () {
resolve("HI")
}, 3000);
});
}).then(function (result) {
console.log(result);
});
I thought it will also print "HI" after 3 seconds. But nothing happened. I thought the second "then" will wait on the the promise in the first "then".
what is wrong for the second example and how to fix it?