Sunday, June 23, 2019

chaining promises

I found this example online:

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;
 
});

No comments:

Post a Comment