feat: RaceCancellation PromiseLike support #4
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.
Last update I removed the ability to pass in an existing promise to RaceCancellation and this adds it back.
The assumption of this library is you don't create promises you are not ready to make part of the current chain. So this was removed to simplify code but the concept of not making promises before you place them into the chain seems like a tough hurdle for people to understand.
When people close over a promise to do
await raceCancellation(() => promise)
when it is already in the cancelled state, it will not invoke the passed in task and create thePromise.race
which is a feature of this library. The issue with this behavior, is if the promise isn't created by the task but closed over, it has the potential to trigger an unhandled promise rejection in this scenario.This change will always create the race regardless of the cancellation state if you pass in a promise like instead of a function which allows you to opt out of the short circuiting.