reliability

package module
v3.0.0-...-caf1bf9 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 14 Imported by: 1 module, 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

Index

Constants

View Source
const (
	DeliveryEvent = "__socketio_reliable_event"
	AckEvent      = "__socketio_reliable_ack"
	PublishEvent  = "__socketio_reliable_publish"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func BindClient

func BindClient(socket *clientsocket.Socket) (*Client, error)

func (*Client) Emit

func (c *Client) Emit(id, name string, args ...any) error

Emit sends a deduplicated client-to-server event. Reusing id is safe.

type Event

type Event struct {
	ID        string    `json:"id" msgpack:"id"`
	Offset    Offset    `json:"offset" msgpack:"offset"`
	Target    Target    `json:"target" msgpack:"target"`
	Name      string    `json:"name" msgpack:"name"`
	Args      []any     `json:"args" msgpack:"args"`
	CreatedAt time.Time `json:"createdAt" msgpack:"createdAt"`
	ExpiresAt time.Time `json:"expiresAt,omitzero" msgpack:"expiresAt,omitempty"`
	Size      int64     `json:"size" msgpack:"size"`
}

type EventStore

type EventStore interface {
	Append(context.Context, Target, *Event) (Offset, error)
	Replay(context.Context, Target, Offset, int) ([]Event, error)
	Ack(context.Context, string, Offset) error
	LastAck(context.Context, string) (Offset, error)
	// MarkInbound returns false when eventID was already processed for clientID.
	MarkInbound(context.Context, string, string, time.Time) (bool, error)
	Prune(context.Context, Limits) error
}

EventStore persists long-lived delivery state. Append must atomically assign an increasing, store-wide offset.

type Limits

type Limits struct {
	Retention time.Duration
	MaxEvents int64
	MaxBytes  int64
}

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Ack

func (s *MemoryStore) Ack(_ context.Context, clientID string, offset Offset) error

func (*MemoryStore) Append

func (s *MemoryStore) Append(_ context.Context, target Target, event *Event) (Offset, error)

func (*MemoryStore) LastAck

func (s *MemoryStore) LastAck(_ context.Context, clientID string) (Offset, error)

func (*MemoryStore) MarkInbound

func (s *MemoryStore) MarkInbound(_ context.Context, clientID, eventID string, expiresAt time.Time) (bool, error)

func (*MemoryStore) Prune

func (s *MemoryStore) Prune(_ context.Context, limits Limits) error

func (*MemoryStore) Replay

func (s *MemoryStore) Replay(_ context.Context, target Target, after Offset, limit int) ([]Event, error)

type Offset

type Offset string

type Options

type Options struct {
	Limits          Limits
	ReplayBatchSize int
	ClientID        func(*serversocket.Socket) string
	UserID          func(*serversocket.Socket) string
	ReplayTargets   func(*serversocket.Socket) []Target
	OnError         func(error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(server *serversocket.Server, store EventStore, opts *Options) (*Service, error)

func (*Service) Close

func (s *Service) Close()

func (*Service) Emit

func (s *Service) Emit(ctx context.Context, target Target, name string, args ...any) (Event, error)

type Target

type Target struct {
	Kind      TargetKind `json:"kind" msgpack:"kind"`
	Namespace string     `json:"namespace" msgpack:"namespace"`
	ID        string     `json:"id,omitempty" msgpack:"id,omitempty"`
}

type TargetKind

type TargetKind string
const (
	TargetNamespace TargetKind = "namespace"
	TargetRoom      TargetKind = "room"
	TargetSocket    TargetKind = "socket"
	TargetUser      TargetKind = "user"
)

Jump to

Keyboard shortcuts

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