Skip to content

Commit

Permalink
Provide cancellation token source to push handler
Browse files Browse the repository at this point in the history
Related to #243.
  • Loading branch information
trowski committed Jan 13, 2020
1 parent e67c725 commit fe17e49
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Expand Up @@ -591,17 +591,20 @@ static function () {
$this->releaseStream($streamId, $exception);
});

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

$onPush = $stream->request->getPushHandler();

try {
yield call($onPush, $stream->request, $stream->pendingResponse->promise());
yield call($onPush, $stream->request, $promise, $tokenSource);
} catch (HttpException | StreamException | CancelledException $exception) {
$tokenSource->cancel($exception);
} catch (\Throwable $exception) {
$tokenSource->cancel($exception);
throw $exception;
} finally {
$cancellationToken->unsubscribe($cancellationId);
}
});
}
Expand Down

0 comments on commit fe17e49

Please sign in to comment.