admin管理员组

文章数量:1393063

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.

本文标签: javascriptchrome debugger promises dont resolve while pausedStack Overflow