chaining promises with await 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: chaining async await
async function test() {
let v1 = await func1();
let v2 = await func2(v1);
return await func3(v1, v2);
}