Skip to content

Commit

Permalink
doc: add a section about contexts and cancellation (#105)
Browse files Browse the repository at this point in the history
Updates #104
  • Loading branch information
creachadair authored Jul 25, 2023
1 parent 2e2c38f commit 31dfd80
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,29 @@ requests are delivered, if they are set.
Since not all clients support server push, handlers should set a timeout when
using the server Callback method; otherwise the callback may block forever for
a client response that will never arrive.
# Contexts and Cancellation
Both the Server and the Client use the standard context package to plumb
cancellation and other request-specific metadata in handlers and calls.
On the server, the context passed to a handler is automatically cancelled when
the server shuts down or when the server's CancelRequest method is invoked for
that request. In addition, the NewContext server option can be used to supply
default timeouts or other context metadata.
On the client, the context passed to the Call and CallResult methods governs
the lifetime of the call. If the context ends before the call is complete, the
client will terminate the call and report an error.
Note that cancellation on the client is not automatically propagated to the
server, as JSON-RPC does not define a standard mechanism to do so. One typical
approach (used by LSP, for example) is to define a separate method on the
server to handle cancellation requests.
If an OnCancel hook is set in the ClientOptions, the client calls it when the
context for a Call ends before the server has responded. This can be used to
forward cancellation to the server separately.
*/
package jrpc2

Expand Down

0 comments on commit 31dfd80

Please sign in to comment.