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

Provide cancellation token source to push handler #245

Closed
wants to merge 1 commit into from

Conversation

trowski
Copy link
Member

@trowski trowski commented Jan 6, 2020

Related to #243.

@@ -594,7 +594,7 @@ static function () {
$onPush = $stream->request->getPushHandler();

try {
yield call($onPush, $stream->request, $stream->pendingResponse->promise());
yield call($onPush, $stream->request, $stream->pendingResponse->promise(), $tokenSource);
Copy link
Member

Choose a reason for hiding this comment

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

Because of the finally below it seems like it's only possible to cancel while the promise returned from $onPush has not resolved, so it doesn't seem to make anything easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

D'oh, yes, that will have to be pushed to the code resolving the promise.

$promise = $stream->pendingResponse->promise();
$promise->onResolve(function () use ($cancellationToken, $cancellationId): void {
$cancellationToken->unsubscribe($cancellationId);
});
Copy link
Member

Choose a reason for hiding this comment

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

This isn't correct either, I guess it has to subscribe to the $response->getTrailers() promise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. This keeps getting more complicated. 😛

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should just keep the current behavior?

Copy link
Member Author

@trowski trowski Jan 13, 2020

Choose a reason for hiding this comment

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

I'm thinking so. The user can return a promise that isn't resolved until they know they want to receive the push.

@nicolas-grekas, you can return a deferred promise from the handler, subsequently failing the deferred to cancel the push.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thank you and sorry for the noise, I should have thought about deferred earlier.

@kelunik
Copy link
Member

kelunik commented Jan 13, 2020

Closing due to #245 (comment).

@kelunik kelunik closed this Jan 13, 2020
@trowski trowski deleted the push-cancellation-token branch April 21, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants