node promise then code example
Example 1: promise chaining
new Promise(function(resolve, reject) {
setTimeout(() => resolve(1), 1000); // (*)
}).then(function(result) { // (**)
alert(result); // 1
return result * 2;
}).then(function(result) { // (***)
alert(result); // 2
return result * 2;
}).then(function(result) {
alert(result); // 4
return result * 2;
});
Example 2: nodejs promise then example
p.then(onFulfilled, onRejected);
p.then(function(value) {
// run
}, function(reason) {
// fail
});