Documentation
¶
Overview ¶
Package dispatch routes addressed deliveries to handlers and provides the request, response and event helpers adapters use. A Dispatcher owns one endpoint attachment and an explicit exact/longest-prefix routing policy; Call and Emit send through any addressed access; Handle and Register run a body per request or event with the context its carrier established.
Index ¶
- func Call(ctx context.Context, access wire.AddressedWire, path []string, ...) error
- func Emit(ctx context.Context, access wire.AddressedWire, path []string, data any, ...) error
- func Handle(registry Registry, path []string, handler Handler) (func(), error)
- func Register(registry Registry, path []string, handlers Handlers) (func(), error)
- type CallOptions
- type Dispatcher
- func (d *Dispatcher) Close(code wire.Code, reason string) error
- func (d *Dispatcher) Register(path []string, receiver wire.Receiver) (func(), error)
- func (d *Dispatcher) RegisterPrefix(path []string, receiver wire.Receiver) (func(), error)
- func (d *Dispatcher) RouteSet() *RouteSet
- func (d *Dispatcher) Select(path []string) *SelectedEndpoint
- func (d *Dispatcher) Send(path []string, message wire.Message) error
- type DispatcherOptions
- type EmitOptions
- type EventHandler
- type Handler
- type Handlers
- type Registry
- type Route
- type RouteSet
- type SelectedEndpoint
- type Served
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(ctx context.Context, access wire.AddressedWire, path []string, params, result any, options ...CallOptions) error
Call sends one request at a relative path and waits for its response, decoding a success into result when it is not nil. Its return capability is fresh for this call and carries the invocation lifecycle, so it is independent of every other call's identifier. A caller that withdraws — ctx ends first — sends a best-effort cancellation. It never retries.
A refusal before anything was sent is an *core.UnpublishedError; a response error is a *core.PublicError.
func Emit ¶
func Emit(ctx context.Context, access wire.AddressedWire, path []string, data any, options ...EmitOptions) error
Emit admits one event at a relative path. Success says only that the destination accepted it; processing and transport remain asynchronous.
Types ¶
type CallOptions ¶
type CallOptions struct {
Propagator core.Propagator
Timeout time.Duration
}
CallOptions configures one call, independently of its carrier. A zero Timeout waits 30 seconds; a nil Propagator uses core.DefaultPropagator.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher owns one endpoint attachment and an explicit exact/longest-prefix routing policy. It captures each request's traversal on the invocation its return capability carries, through the public vocabulary alone, and refuses a request whose return capability carries none rather than routing it with weaker detach and cancellation guarantees. An opaque wrapper is therefore as good as a native endpoint: the lifecycle travels with the unchanged return capability, and nothing here recognizes a concrete type. A cancellation goes to the traversal that captured its request, never to the route now in force.
func NewDispatcher ¶
func NewDispatcher(root wire.Endpoint, options ...DispatcherOptions) (*Dispatcher, error)
NewDispatcher attaches to root and routes what it delivers. The endpoint is borrowed unless options transfer its closure.
func (*Dispatcher) Close ¶
func (d *Dispatcher) Close(code wire.Code, reason string) error
Close releases the routes and the root attachment, and closes the root only when this dispatcher owns it.
func (*Dispatcher) Register ¶
func (d *Dispatcher) Register(path []string, receiver wire.Receiver) (func(), error)
Register routes exactly path to receiver. A path has one registration.
func (*Dispatcher) RegisterPrefix ¶
func (d *Dispatcher) RegisterPrefix(path []string, receiver wire.Receiver) (func(), error)
RegisterPrefix routes path and every path beneath it, the longest registered prefix winning, unless an exact registration matches.
func (*Dispatcher) RouteSet ¶ added in v0.3.0
func (d *Dispatcher) RouteSet() *RouteSet
RouteSet returns an empty group of routes owned by its caller.
func (*Dispatcher) Select ¶
func (d *Dispatcher) Select(path []string) *SelectedEndpoint
Select returns a receiving view of this shared dispatcher. The view owns its prefix route and never acquires closure authority over the root endpoint.
type DispatcherOptions ¶
type DispatcherOptions struct{ OwnEndpoint bool }
DispatcherOptions explicitly transfers closure authority for an endpoint the caller owns. Borrowed endpoints remain the default.
type EmitOptions ¶
type EmitOptions struct {
Propagator core.Propagator
}
EmitOptions configures one event emission; a nil Propagator uses core.DefaultPropagator.
type EventHandler ¶
type EventHandler func(context.Context, json.RawMessage) error
EventHandler receives an event body beside the context it was carried with. An error ends the registry's endpoint as a protocol error.
type Handler ¶
Handler is a request body, independent of the carrier. It takes the params as they arrived and returns the result, or an error: a *core.PublicError crosses with its code, a cancellation as cancelled, and any other error as internal. Its context carries the trace and meta the request brought, and ends when the caller withdraws or the deadline passes.
type Handlers ¶
type Handlers struct {
Request Handler
Event EventHandler
}
Handlers groups a request body and an event body that share one path.
type Registry ¶
type Registry interface {
wire.AddressedWire
Register([]string, wire.Receiver) (func(), error)
Close(wire.Code, string) error
}
Registry is the registration capability Handle and Register need: send access plus explicit route registration. Closing it releases its registrations, not a borrowed carrier.
type RouteSet ¶ added in v0.3.0
type RouteSet struct {
// contains filtered or unexported fields
}
RouteSet is a group of routes its owner replaces as a whole. Set swaps the group's routes under the dispatcher's lock, so each delivery is routed by the group before the swap or by the group after it, never by a mixture and never by neither. A request already admitted keeps the registration that admitted it: its cancellation reaches that route's receiver, whatever has replaced it since. Replacing or removing a route does not call its Closed; closing the dispatcher does.
func (*RouteSet) Close ¶ added in v0.3.0
func (s *RouteSet) Close()
Close removes the group's routes. The group admits no further Set.
func (*RouteSet) Set ¶ added in v0.3.0
Set replaces every route of the group with routes, atomically. It refuses, changing nothing, an invalid path (core.ErrInvalidPath), a path given twice or registered outside the group (core.ErrReceiverExists), and a closed group or dispatcher (transports.ErrClosed).
type SelectedEndpoint ¶
type SelectedEndpoint struct {
// contains filtered or unexported fields
}
SelectedEndpoint is a receiving view of a shared dispatcher at a prefix.
func (*SelectedEndpoint) Close ¶
func (s *SelectedEndpoint) Close(code wire.Code, reason string) error
Close ends the view's route; it never closes the shared root.
func (*SelectedEndpoint) Receive ¶
func (s *SelectedEndpoint) Receive(receiver wire.Receiver) (func(), error)
Receive attaches the view's one receiver, which sees paths relative to the view's prefix.
func (*SelectedEndpoint) Select ¶
func (s *SelectedEndpoint) Select(path []string) *SelectedEndpoint
Select narrows the view by a further prefix.
type Served ¶ added in v0.3.0
type Served struct {
// contains filtered or unexported fields
}
Served is a WireTree served on a dispatcher beneath a prefix.
func Serve ¶ added in v0.3.0
Serve routes each position of tree through one exact route beneath prefix, bound to that position's own Wire, so what a peer sends at prefix ++ path reaches select(tree, path).own(). A node shared by two positions is served at both: a carrier path names a position, not a node.
A child whose key is not UTF-8 cannot be named by a bitwire/1 path; it and its whole subtree are left unserved and listed by Unreachable. A request its node's own refuses is answered with that refusal, as internal unless it is a PublicError. A refused event is dropped, as an event nothing handles is; it never ends the carrier. Cancellation is not routed here: the dispatcher hands it to the route that admitted its request.
The prefix is nonempty, since bitwire/1 names no request or event at the empty path. Serve validates the tree's complete child graph and refuses a missing own Wire. Neither Serve nor Close closes the dispatcher or its endpoint.
func (*Served) Close ¶ added in v0.3.0
func (s *Served) Close()
Close stops serving. Requests already admitted still reach their nodes.
func (*Served) Unreachable ¶ added in v0.3.0
Unreachable lists, relative to the tree, the positions of children whose key is not UTF-8 and which are therefore not served, with their subtrees.
func (*Served) Update ¶ added in v0.3.0
Update serves tree in place of the tree served now, in one step: each delivery is routed by the old tree or by the new one, never by neither, and a request admitted before the update keeps the node that admitted it, its cancellation included. A refused update leaves the served tree unchanged.