internal/mcp/design: add a section on cancellation
Change-Id: If18a7d8efa37a6f34ae42f4d1896464800ebcdc7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/671435 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
c8966c94f3
commit
e2248b0f80
1 changed files with 14 additions and 1 deletions
|
|
@ -420,7 +420,20 @@ func (*Server) Run(context.Context, Transport)
|
||||||
|
|
||||||
### Cancellation
|
### Cancellation
|
||||||
|
|
||||||
<!-- TODO: a brief section discussing how cancellation is handled. -->
|
Cancellation is implemented transparently using context cancellation. The user
|
||||||
|
can cancel an operation by cancelling the associated context:
|
||||||
|
|
||||||
|
```go
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
go session.CallTool(ctx, "slow", map[string]any{})
|
||||||
|
cancel()
|
||||||
|
```
|
||||||
|
|
||||||
|
When this client call is cancelled, a `"notifications/cancelled"` notification
|
||||||
|
is sent to the server. However, the client call returns immediately with
|
||||||
|
`ctx.Err()`: it does not wait for the result from the server.
|
||||||
|
|
||||||
|
The server observes a client cancellation as cancelled context.
|
||||||
|
|
||||||
### Progress handling
|
### Progress handling
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue