In order to chain you must return
a promise or else it's presumed to be something that's not relevant to the chain:
console.log(`calling fn #1`);
fn1(2000).then(()=>{
console.log(`calling fn #2`);
return fn(2000);
}).then(()=>{
console.log(`calling fn #3`);
return fn(2000);
});
Also if you want the await
form it looks like this:
async function example() {
console.log(`calling fn #1`);
await fn1(2000);
console.log(`calling fn #2`);
await fn(2000);
console.log(`calling fn #3`);
await fn(2000);
};
Which honestly is a lot cleaner.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…