-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Conversation
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
9718e94
to
fe17e49
Compare
$promise = $stream->pendingResponse->promise(); | ||
$promise->onResolve(function () use ($cancellationToken, $cancellationId): void { | ||
$cancellationToken->unsubscribe($cancellationId); | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 😛
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Closing due to #245 (comment). |
Related to #243.