4 ms·
Debugging is a bit of a challenge with promises. Indeed, and that is why I am personally not really that bullish on promises, at least not how they are current
by javajosh 12y ago
Debugging is a bit of a challenge with promises.
Indeed, and that is why I am personally not really that bullish on promises, at least not how they are currently implemented. When you're debugging you want access to the implicit state-machine that the promise statement constructed, but at least in JS such state is hidden away in the `then()` function.
A good compromise (which I'm currently exploring in JS) is to make the state-machine navigable from the root, giving you the ability to examine it and mutate it explicitly during a debug session.
- chaitanya 12y ago> A good compromise (which I'm currently exploring in JS) is to make the state-machine navigable from the root, giving you the ability to examine it and mutate it explicitly during a debug session. You might also want to check out the JS library q, which has support for stack traces that span async jumps if a promise errors out https://github.com/kriskowal/q#long-stack-traces https://github.com/kriskowal/q#long-stack-traces
- Arnavion 12y agoLibraries like bluebird will give you pretty stack traces that track the sequence of then calls, almost as if it was a single sequential execution. This helps with debugging. Alternatively you can use the yield-spawn method of getting rid of then() altogether. Then you get code that looks sequential as well, and the browser gives you nice stack traces. This doesn't help with modifying values during debugging as you mentioned, but it does solve the problem of seeing the "caller" stack frames.