1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-10-14 19:26:46 +02:00
jsonrpc2/async.go
Keegan Carruthers-Smith bf8fe04036
docs/conn: clarify ordering guarantees for bidirectional calls (#105)
Users can otherwise mistake transport ordering for application-level synchronization and attempt blocking calls from the synchronous read loop.
2026-09-10 09:43:30 +02:00

18 lines
469 B
Go

package jsonrpc2
import "context"
// AsyncHandler wraps a Handler such that each request is handled in its own
// 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}
}
type asyncHandler struct {
Handler
}
func (h asyncHandler) Handle(ctx context.Context, conn *Conn, req *Request) {
go h.Handler.Handle(ctx, conn, req)
}