最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - chrome debugger promises dont resolve while paused? - Stack Overflow

programmeradmin3浏览0评论

Maybe I'm not debugging promises right but basically if you stop at break point and run async code it doesnt actually finishes until you resume execution and that's a problem. Debugger allows you to quickly experiment with multiple api methods... but you cant if you resume it

debugger;
//now type the following in console
Promise.resolve().then(()=> console.log('done'));

Maybe I'm not debugging promises right but basically if you stop at break point and run async code it doesnt actually finishes until you resume execution and that's a problem. Debugger allows you to quickly experiment with multiple api methods... but you cant if you resume it

debugger;
//now type the following in console
Promise.resolve().then(()=> console.log('done'));
Share Improve this question edited Nov 10, 2017 at 5:48 Muhammad Umer asked Nov 10, 2017 at 5:42 Muhammad UmerMuhammad Umer 18.2k24 gold badges111 silver badges176 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

A possible workaround for this is to put debugger in your .then callback as well. This won't work in all situations but it worked for my particular case of debugging node.js scripts before they exit:

  1. insert this into the JS code that you want to debug

    debugger;
    
  2. when the debugger stops, type the following at the console prompt:
    expressionReturningPromise().then( r => {
      console.log('done');
      debugger;
    });
    
  3. resume script execution

The dev tools will then pause on the debugger within the .then callback and you'll have the resolved value of your promise available for examination.

It doesn't execute because the function in .then is only called when the current "thread" is finished. This is the same for all asynchronous calls such as setTimeout.

发布评论

评论列表(0)

  1. 暂无评论