简体   繁体   English

打字稿异步等待调试

[英]Typescript async await debugging

I have a strange issue in my code and I'm unable to root cause it.我的代码中有一个奇怪的问题,我无法找出根本原因。

try {
    const result = await somePromise.catch((err) => {
        console.log(new Date()); // this prints time, t0
        console.log('Stats', eventLoopStats.sense());
        throw err;
    });
} catch (e) {
    console.log(new Date()); // this prints time, t0 + 15 seconds
    console.log('Stats', eventLoopStats.sense()); // this prints {0, 0, 0, 0}, meaning, event loop hasn't been involved since last call to sense
}

My question is, why is there a huge lag between the promise rejecting and it actually being caught in the outer catch block?我的问题是,为什么在拒绝承诺和实际被外部 catch 块捕获之间存在巨大的滞后?

I'm in my dev environment, which is fairly idle.我在我的开发环境中,这是相当空闲的。 Also, it is consistently has around 15 second delay.此外,它始终有大约 15 秒的延迟。

Are there any other debugging approaches?还有其他调试方法吗?

Notes:笔记:

  1. I'm using node version 12.11.1我正在使用节点版本 12.11.1
  2. Also using bluebird for promises还使用bluebird进行承诺
  3. somePromise is obtained from a library which was transpiled into Javascript from Typescript. somePromise是从从 Typescript 转译为 Javascript 的库中获得的。

The root cause was that my code had monkey patched promise binding which caused code to be injected between the promise rejection and continuation of the event loop.根本原因是我的代码对 promise 绑定进行了猴子修补,这导致代码在 promise 拒绝和事件循环的继续之间注入。 If you have a similar issue, check if your code has patched Promise.bind .如果您遇到类似问题,请检查您的代码是否已修补Promise.bind

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM