mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-16 04:04:56 +02:00
Handle is blocking (#12)
NOTE: This is a breaking change to the expected contract of Handler. Please update your implementation to use AsyncHandler if needs be. We have strict ordering requirements of how we handle FileSystem requests in LSP. As such relying on the ordering the goroutine scheduler runs requests in leads to potential out of order mutations to the FS. As such we update the jsonrpc2 implementation to by default block until Handle returns (note it can still respond to the request at a later stage). For more simple use cases we provide the AsyncHandler which will work like the previous implementation. * Ensure handle is blocking
This commit is contained in:
parent
277d2464cf
commit
3a7c446248
3 changed files with 75 additions and 4 deletions
|
|
@ -226,7 +226,10 @@ const (
|
|||
|
||||
// Handler handles JSON-RPC requests and notifications.
|
||||
type Handler interface {
|
||||
// Handle is called to handle a request.
|
||||
// Handle is called to handle a request. No other requests are handled
|
||||
// until it returns. If you do not require strict ordering behaviour
|
||||
// of received RPCs, it is suggested to wrap your handler in
|
||||
// AsyncHandler.
|
||||
Handle(context.Context, *Conn, *Request)
|
||||
}
|
||||
|
||||
|
|
@ -498,7 +501,7 @@ func (c *Conn) readMessages(ctx context.Context) {
|
|||
if c.onRecv != nil {
|
||||
c.onRecv(m.request, nil)
|
||||
}
|
||||
go c.h.Handle(ctx, c, m.request)
|
||||
c.h.Handle(ctx, c, m.request)
|
||||
|
||||
case m.response != nil:
|
||||
resp := m.response
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue