Fix issue with Futures created from Promises #310
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fix makes it so when the
fork
,value
,done
, orpromise
functions throw an exception as a result of the Future entering a
crashed state, the exception is thrown in the next tick.
This means that if a Promise was used anywhere in the pipeline, we can
ensure that it does not get the opportunity to catch this exception.
The reason we want to avoid this, is because the Promise continuations
are already handled by Fluture, and if the Promise catches this
exception, it will start handling it in its own way, by emitting an
unhandledRejection event on some global event emitter.
This exact issue has been fixed before, and then optimized in #150. It was later removed in #224 for the reasons listed in #224 (comment). I now believe this was a mistake, and the benefit mentioned in that comment is too minor to weigh against the issue it creates.