Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownCommunicationType = fmt.Errorf("unknown communication type")
Functions ¶
This section is empty.
Types ¶
type CommunicationConfig ¶
type CommunicationConfig struct {
Type CommunicationType `json:"type"`
UnixDomain *UnixDomainConfig `json:"unix_domain,omitempty"`
}
type CommunicationType ¶
type CommunicationType int
const ( UnixDomain CommunicationType = iota Pipe )
type Data ¶
type Data[T any] struct { Id string // Subscription identifier Payload T // The actual data to deliver }
Data represents a message with an identifier and a payload of generic type T. Used to deliver results to subscribers.
type Dispatcher ¶
type Dispatcher[T any] struct { // contains filtered or unexported fields }
Dispatcher is a generic, thread-safe, single-use subscription manager. It allows clients to subscribe for a result by Id and asynchronously receive the result when it becomes available (e.g., from a socket-based service).
func NewDispatcher ¶
func NewDispatcher[T any](bufferSize int) *Dispatcher[T]
NewDispatcher creates a new Dispatcher with the specified buffer size for internal channels. The buffer size should be chosen based on expected concurrency and throughput.
func (*Dispatcher[T]) Enqueue ¶
func (l *Dispatcher[T]) Enqueue(id string) <-chan T
Enqueue registers a new subscription for the given Id. It returns a channel that will receive the result when available. The channel will be closed after the result is sent or if the subscription is cancelled. Only one outstanding subscription per Id is allowed at a time.
func (*Dispatcher[T]) Post ¶
func (l *Dispatcher[T]) Post(data Data[T])
Post delivers a result to the subscription with the matching Id. If a subscription exists, the result is sent and the channel is closed.
func (*Dispatcher[T]) Run ¶
func (l *Dispatcher[T]) Run(ctx context.Context) (context.CancelFunc, <-chan struct{})
Run starts the subscription event loop in a new goroutine. It listens for new subscriptions and results, and matches them by Id. When the context is cancelled, all open subscription channels are closed and the loop exits. Returns a CancelFunc to stop the loop and a channel that is closed when the loop exits.
type EventQueue ¶
type QAPIEvent ¶
type QAPIEvent struct {
Event string `json:"event,omitempty"`
Data json.RawMessage `json:"data"`
Timestamp *struct {
Seconds int64 `json:"seconds"`
Microseconds int64 `json:"microseconds"`
} `json:"timestamp"`
}
type QAPIResult ¶
type QAPIResult struct {
Id string `json:"id,omitempty"`
Error *Error `json:"error,omitempty"`
Return json.RawMessage `json:"return,omitempty"`
}
type RawResponse ¶
type RawResponse struct {
QAPIResult
QAPIEvent
}
type Request ¶
type Request struct {
Id string `json:"id,omitempty"`
Execute string `json:"execute"`
Arguments json.RawMessage `json:"arguments,omitempty"`
}
type Subscription ¶
type Subscription[T any] struct { Id string // Subscription identifier Payload chan T // Channel to receive the result }
Subscription represents a request to subscribe to a result with a given Id. The result will be delivered on the Payload channel.
type UnixDomainConfig ¶
type UnixDomainConfig struct {
SocketPath string
}