MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / Await

Method Await

internal/jsonrpc2/conn.go:399–412  ·  view source on GitHub ↗

Await waits for (and decodes) the results of a Call. The response will be unmarshaled from JSON into the result. If the call is cancelled due to context cancellation, the result is ctx.Err().

(ctx context.Context, result any)

Source from the content-addressed store, hash-verified

397// If the call is cancelled due to context cancellation, the result is
398// ctx.Err().
399func (ac *AsyncCall) Await(ctx context.Context, result any) error {
400 select {
401 case <-ctx.Done():
402 return ctx.Err()
403 case <-ac.ready:
404 }
405 if ac.response.Error != nil {
406 return ac.response.Error
407 }
408 if result == nil {
409 return nil
410 }
411 return json.Unmarshal(ac.response.Result, result)
412}
413
414// Cancel cancels the Context passed to the Handle call for the inbound message
415// with the given ID.

Callers 1

callFunction · 0.80

Calls 3

UnmarshalFunction · 0.92
DoneMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected