Skip to content

Commit

Permalink
Merge pull request #2592 from murgatroid99/example_cancellation_fix
Browse files Browse the repository at this point in the history
Cancellation example: corrected information
  • Loading branch information
murgatroid99 authored Oct 2, 2023
2 parents f7d9baa + 2003c88 commit 8374364
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/cancellation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

This example shows how clients can cancel in-flight RPCs by cancelling the
call object returned by the method invocation. The client will receive a status
with code `CANCELLED` and the server handler's call object will emit a
`'cancelled'` event.
with code `CANCELLED` and the server handler's call object will emit either a
`'cancelled'` event or an `'end'` event.

## Start the server

Expand Down
4 changes: 3 additions & 1 deletion examples/cancellation/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ function bidirectionalStreamingEcho(call) {
console.log(`echoing message "${message}"`);
call.write({message: message});
});
// Either 'end' or 'cancelled' will be emitted when the call is cancelled
call.on('end', () => {
console.log('server received end event')
call.end();
});
call.on('cancelled', () => {
console.log('received cancelled event');
console.log('server received cancelled event');
});
}

Expand Down

0 comments on commit 8374364

Please sign in to comment.