I am reading the article about nodejs promise here.
Then I try running the following sample code (from the article)
const p = Promise.resolve();
(async () => {
await p; console.log('after:await');
})();
p.then(() => console.log('tick:a'))
.then(() => console.log('tick:b'));
The results are inconsistent between node versions. With node v10 staying out of all other versions.
I am using a mac.
v8.17.0
after:await
tick:a
tick:b
v10.20.1
tick:a
tick:b
after:await
v12.17.0
after:await
tick:a
tick:b
v14.3.0
after:await
tick:a
tick:b
The article says that v10 introduces a breaking change to correct the execution order and the behavior of v8 is a bug. However, when I tested with v12 and v14, they give the same result as v8.
Could anyone explain to me why this happens?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…