我对下面的代码有一个奇怪的问题:在函数调用之后添加一个无限循环将阻止在调用内部解决承诺。
我不明白为什么,以及这个循环如何影响承诺行为
const second_call = () => {
return new Promise((resolve, reject) => {
console.log("Second call");
resolve();
});
}
const first_call = () => {
console.log("First call");
second_call().then(() => {
console.log("First call, THEN");
});
}
const main = () => {
console.log("Started");
first_call();
//if if comment the while (true), all debug msgs will be displayed
//if i uncomment the while (true), the msg "First call, THEN" will not be displayed
while (true);
}
main();
Run Code Online (Sandbox Code Playgroud)