Open overlookmotel opened 6 years ago
Honestly I'd expect .coroutine
to always defer being called by a microtick. The surprising part to me here is that it doesn't do that.
Do you mean that you'd expect the generator function not to be called immediately (synchronously) when the coroutine is called? i.e. you'd expect this:
const fn = Promise.coroutine( function*() {
console.log('generator function called');
});
fn();
console.log('next line');
to output:
next line
generator function called
Personally, I feel the current behaviour is correct - that the generator function should be called synchronously. I believe this matches the behaviour of async/await.
Thanks for swift reply, by the way.
It does match the behavior of async/await. I guess that it might as well be synchronous in the stack trace. @petkaantonov ?
Please answer the questions the best you can:
1) What version of bluebird is the issue happening on?
v3.5.1
2) What platform and version? (For example Node.js 0.12 or Google Chrome 32)
Node 6.12.2, Mac OS 10.12.6
3) Did this issue happen with earlier version of bluebird?
Unknown
This is a very small nit.
When long stack traces are enabled, the stack trace for an error thrown synchronously in a coroutine includes "From previous event" when in fact everything happened synchronously.
Produces error:
Without long stack traces enabled, error trace is:
The source of the problem appears to be this line where
._rejectCallback()
is always called withsynchronous = false
regardless of whether error is thrown sync or not.