I am trying to learn how to use promises, but I have problems understanding the chain. I assume that both promises will be executed with this code. Then, when I call test.then (), it should know that the test has resolved and pass then () permission data.
As soon as this function ends, it moves on to the next, then (), repeating the same process with the promise test2.
However, I can only get it to print the results of the first promise, not the second. Any ideas what's missing here?
var test = new Promise(function(resolve, reject){
resolve('done1');
});
var test2 = new Promise(function(resolve, reject){
resolve('done2');
});
test
.then(function(data) {
console.log(data);
})
.then(test2)
.then(function(data) {
console.log(data);
});
source
share