【问题标题】:Why is this code getting into an infinte loop?为什么这段代码会陷入无限循环?
【发布时间】:2022-08-19 00:06:31
【问题描述】:
process.on(\'beforeExit\', (code) => {
    setTimeout(() => {
      console.log(\'This will make strange behaviour\');
    });
  });

Output Shown

    标签: javascript node.js callback backend event-loop


    【解决方案1】:

    尝试这个:

    process.on('beforeExit', (code) => {
    setTimeout(() => {
      console.log('This will make strange behaviour');
    }, 3000);
    });
    

    【讨论】:

    • 有什么不同?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 2021-09-18
    相关资源
    最近更新 更多