1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-10-26 15:46:45 +01:00

docs/conn: clarify ordering guarantees for bidirectional calls

Users can otherwise mistake transport ordering for application-level synchronization and attempt blocking calls from the synchronous read loop.

Amp-Thread-ID: https://ampcode.com/threads/T-01a08a2e-db35-72f9-a070-6c28f8e88fe0
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Keegan Carruthers-Smith 2026-09-10 09:27:51 +02:00
parent fb2b860c84
commit 77705d286c
No known key found for this signature in database
3 changed files with 11 additions and 6 deletions

View file

@ -3,7 +3,8 @@ package jsonrpc2
import "context"
// AsyncHandler wraps a Handler such that each request is handled in its own
// goroutine. It is a convenience wrapper.
// goroutine. Handlers may therefore start or finish in a different order than
// requests are received. It is a convenience wrapper.
func AsyncHandler(h Handler) Handler {
return asyncHandler{h}
}

View file

@ -156,7 +156,9 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}, op
return err
}
// Reply sends a successful response with a result.
// Reply sends a successful response with a result. It returns after writing
// the response to the ObjectStream; it does not wait for the peer to receive or
// process the response.
func (c *Conn) Reply(ctx context.Context, id ID, result interface{}) error {
resp := &Response{ID: id}
if err := resp.SetResult(result); err != nil {

View file

@ -59,10 +59,12 @@ const (
// Handler handles JSON-RPC requests and notifications.
type Handler interface {
// Handle is called to handle a request. No other requests are handled until
// it returns. If you do not require strict ordering behavior of received
// RPCs, it is suggested to wrap your handler in AsyncHandler. The context
// is automatically canceled when the connection closes.
// Handle is called to handle a request. While it is running, the connection
// does not process any other requests or responses. A handler that waits for
// a call's response must therefore run asynchronously. If you do not require
// strict ordering behavior of received RPCs, it is suggested to wrap your
// handler in AsyncHandler. The context is automatically canceled when the
// connection closes.
Handle(context.Context, *Conn, *Request)
}