Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RaceCancellation PromiseLike support #4

Merged
merged 1 commit into from
May 23, 2019
Merged

Conversation

krisselden
Copy link
Owner

@krisselden krisselden commented May 20, 2019

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 the Promise.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.

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 the `Promise.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.
@krisselden krisselden merged commit b764ed7 into master May 23, 2019
@krisselden krisselden deleted the feat-race-promise branch June 18, 2019 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant