mcp: implement a concurrency model for calls
Implement the concurrency model described in #26: notifications are synchronous, but calls are asynchronous (except for 'initialize'). To achieve this, implement jsonrpc2.Async(ctx) to signal asynchronous handling. This is simpler to use than returning ErrAsyncResponse and calling Respond, and since this is an internal detail we don't need to worry too much about whether it's idiomatic. Add tests that verify both features, for both client and server. Also: - replace req.ID.IsValid with req.IsCall - remove the methodHandler type as we can just use MethodHandler Fixes #26
This commit is contained in:
parent
112ca4e3b1
commit
3db848abec
1 changed files with 208 additions and 86 deletions
|
|
@ -22,13 +22,6 @@ var (
|
|||
// If a Handler returns ErrNotHandled, the server replies with
|
||||
// ErrMethodNotFound.
|
||||
ErrNotHandled = errors.New("JSON RPC not handled")
|
||||
|
||||
// ErrAsyncResponse is returned from a handler to indicate it will generate a
|
||||
// response asynchronously.
|
||||
//
|
||||
// ErrAsyncResponse must not be returned for notifications,
|
||||
// which do not receive responses.
|
||||
ErrAsyncResponse = errors.New("JSON RPC asynchronous response")
|
||||
)
|
||||
|
||||
// Preempter handles messages on a connection before they are queued to the main
|
||||
|
|
|
|||
Loading…
Reference in a new issue