If I type debugger and I want to check something. But call to that function returns a promise, then i am stuck.
For example:
I typed debugger and it stopped.
function test(db) {
debugger;
// here i want to see something
var a = .....;
}
But if I type
let d = db.User.create();
I'll get
Promise { pending }
now there is no recourse. I can't simply evaluate promise. Kinda make whole debugger less useful.
This would have been no problem, if it was synchronous, I'd have been able to jump in mid program, check out few things and modify program to my liking then run rest of the program.
The Promise. resolve() method "resolves" a given value to a Promise . If the value is a promise, that promise is returned; if the value is a thenable, Promise. resolve() will call the then() method with two callbacks it prepared; otherwise the returned promise will be fulfilled with the value.
They can handle multiple asynchronous operations easily and provide better error handling than callbacks and events. In other words also, we may say that, promises are the ideal choice for handling multiple callbacks at the same time, thus avoiding the undesired callback hell situation.
As you can see, Promise. all executes code concurrently, but what is parallel execution? JavaScript is single-threaded and can only perform a single chunk of work at a time, so parallel execution is not possible with JavaScript, except for some circumstances such as web workers.
Probably in order to understand why promises can't be resolved while debugger is paused, you need to understand how Event Loop works. There are plenty of resources about it so no need to explain it here.
When you pause a Debugger, Event Loop gets paused too. And everything asynchronous is scheduled and handled in Event Loop.
Possible ways to resolve promise in debugger:
Unfortunately at the moment best and simplest ways I am aware of are:
db.User.create().then(x => global.a = x);
// use global.a as you'd like:
console.log(global.a);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With