Documentation
¶
Overview ¶
Package rpc runs request/response/notification exchanges over a wire.Codec: a Client for the calling side and Serve for the serving side.
Index ¶
- Variables
- func Decode(m *wire.Msg, v any) error
- func Serve(ctx context.Context, rw io.ReadWriteCloser, h Handler) error
- type Client
- func (c *Client) Call(ctx context.Context, method string, params, result any) error
- func (c *Client) CallRaw(ctx context.Context, method string, params json.RawMessage) (*wire.Msg, error)
- func (c *Client) Close() error
- func (c *Client) Codec() *wire.Codec
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Err() error
- func (c *Client) Go(method string, params json.RawMessage, onResponse func(*wire.Msg))
- func (c *Client) Notify(method string, params any) error
- type Conn
- type Handler
Constants ¶
This section is empty.
Variables ¶
var Async = &struct{ async bool }{true}
Async, returned by a Handler as its result, means the handler will answer the request itself later via Conn.Reply / Conn.ReplyError (typically from a goroutine, so a slow request does not block the connection).
var ErrClosed = errors.New("rpc: connection closed")
ErrClosed is returned by calls on a closed client.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client issues requests and dispatches incoming notifications.
func NewClient ¶
func NewClient(rw io.ReadWriteCloser, onNotify func(*wire.Msg)) *Client
NewClient starts reading rw. onNotify (may be nil) receives every notification, sequentially, on the read goroutine — it must not block for long. Incoming requests are answered with unknown_method.
func (*Client) Call ¶
Call sends a request and decodes the result into result (may be nil). A protocol error is returned as *wire.Error.
func (*Client) CallRaw ¶
func (c *Client) CallRaw(ctx context.Context, method string, params json.RawMessage) (*wire.Msg, error)
CallRaw sends a request with raw params and returns the raw response message (Result or Error set). Used by the bridge to forward verbatim.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done is closed when the connection ends.
func (*Client) Go ¶
Go sends a request without waiting for it. onResponse is called exactly once: with the response on the read goroutine — before any later message of the connection is dispatched, so a forwarded response stays ordered with the notifications around it — or with nil when the request could not be sent or the connection ended first. It must not block for long.