client

package
v0.0.0-...-8321b74 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownCommunicationType = fmt.Errorf("unknown communication type")

Functions

This section is empty.

Types

type Action

type Action int
const (
	ActionAdd Action = iota
	ActionCancel
	ActionClose
	ActionExecute
)

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 Error

type Error struct {
	Class       string `json:"class"`
	Description string `json:"desc"`
}

type Event

type Event struct {
	Id     string
	Data   []string
	Error  error
	Action *Action
}

type EventQueue

type EventQueue interface {
	Wait(context context.Context) (iter.Seq[*Event], error)
	Add(id string, config CommunicationConfig) error
	Execute(id string, request Request) error
	Cancel(requestId string) error
	Close() error
}

type Null

type Null struct{}

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 QEmpty

type QEmpty struct{}

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 Response

type Response[T any] struct {
	Id     string `json:"id,omitempty"`
	Error  string `json:"error,omitempty"`
	Return T      `json:"return,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
}

Jump to

Keyboard shortcuts

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