function sampleResolve(value) {
return new Promise(resolve => {
setTimeout(() => {
resolve(value);
}, 1000);
})
}
function sample() {
let result = 0;
return sampleResolve(5)
.then(val => {
console.log(result, val)
result += val;
return sampleResolve(10);
})
.then(val => {
console.log(result, val)
result *= val;
return sampleResolve(20);
})
.then(val => {
console.log(result, val)
result += val;
return result;
});
}
sample().then((v) => {
console.log(v); // => 70
});
0 5
5 10
50 20
70