dispatch

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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.

func Handle

func Handle(registry Registry, path []string, handler Handler) (func(), error)

Handle registers one request body at a relative path. The receiver returns before running application code; the body runs asynchronously, and the request's cancellation reaches it through its return capability.

func Register

func Register(registry Registry, path []string, handlers Handlers) (func(), error)

Register installs one receiver for a request body, an event body, or both, at a relative path. The one detach removes the group; an event-only path refuses requests with method_not_found.

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) 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.

func (*Dispatcher) Send

func (d *Dispatcher) Send(path []string, message wire.Message) error

Send sends through the borrowed root.

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

type Handler func(context.Context, json.RawMessage) (any, error)

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 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.

func (*SelectedEndpoint) Send

func (s *SelectedEndpoint) Send(path []string, message wire.Message) error

Send sends beneath the view's prefix through the shared root.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL