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

Backport promise cancellation support to v1 Promise API #48

Merged
merged 6 commits into from Feb 27, 2016

Conversation

clue
Copy link
Member

@clue clue commented Feb 26, 2016

This is an independent backport of promise cancellation support for the legacy v1 Promise API. It implements the same API as originally implemented in #20, but does not share a single line of code. Original concept courtesy of @jsor.

The main purpose here is backwards compatibility for promise consumers, which can rely on the cancellation API to be available for newer v2 as well as legacy v1 promises.

@jsor
Copy link
Member

jsor commented Feb 26, 2016

👍

@clue
Copy link
Member Author

clue commented Feb 26, 2016

This now also contains the fix from #47 so that the cancellation handler will not be called more than once.

Ready for review :shipit:


$canceller = $this->canceller;
$this->canceller = null;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, you should check here for is_callabe($canceller) and trigger a notice when false like done here, here and here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could throw in the constructor, similar to here.

@clue
Copy link
Member Author

clue commented Feb 27, 2016

Thanks for the hint @jsor, makes perfect sense 👍 I've just pushed an update, I've decided to throw an InvalidArgumentException to be more in line with how the Promise rejects invalid constructors arguments.

jsor added a commit that referenced this pull request Feb 27, 2016
Backport promise cancellation support to v1 Promise API
@jsor jsor merged commit d360822 into reactphp:1.0 Feb 27, 2016
@clue clue deleted the cancellable branch March 25, 2016 15:52
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

2 participants