sync

package
v0.0.0-...-b5230d3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

sync package implements an abstraction over `isalink.IsaClient` that is safe for concurrent use it is intended for use with multiple readers that await asynchronous commands

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateRegistration = errors.New("registration for this id already present")
	ErrMissingRegistration   = errors.New("registration missing")
)
View Source
var (
	ErrClientInit    = errors.New("client not fully initialized")
	ErrTooManyTasks  = errors.New("tasks slots exhausted for this client")
	ErrReservedID    = errors.New("uuid.Nil/sync.SyncID is reserved for internal use")
	ErrInvalidFilter = errors.New("a filter must be valid func reference")
)
View Source
var ErrCancelTask = errors.New("failed to cancel an async isabelle task")
View Source
var ErrShutdown = errors.New("failed to shutdown server")
View Source
var ErrTickRace = errors.New("multiple ticks scheduled, corrupt state")
View Source
var ErrWriterClosed = errors.New("message producer closed")
View Source
var SyncID = uuid.Nil

reserved ID for sync task dispatch/message filters

Functions

This section is empty.

Types

type ErrDispatchFailed

type ErrDispatchFailed struct {
	Msg *isalink.ServerMessage
}

error with error message for task dispatch

func (*ErrDispatchFailed) Error

func (err *ErrDispatchFailed) Error() string

type Filter

type Filter = func(*isalink.ServerMessage) bool

a filter for listeners, message with filter(msg) == true are returned to the listener channel

type SyncClient

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

mt-safe client for asynchronous task dispatch, can be created with WrapClient

func WrapBoundedClient

func WrapBoundedClient(client *isalink.IsaClient, slots int64) *SyncClient

create new sync client from isalink.IsaClient with a fixed limit on concurrent async tasks

func WrapClient

func WrapClient(client *isalink.IsaClient) *SyncClient

create new sync client from isalink.IsaClient

func (*SyncClient) AsyncCommand

func (sc *SyncClient) AsyncCommand(
	ctx context.Context,
	logger log.Logger,
	msg *isalink.ClientMessage,
) (uuid.UUID, <-chan *isalink.ServerMessage, error)

Dispatch asynchronous command and return task ID + listener channel

NOTE: if bounded tasks are set then this will block on waiting for a task slot, if all slots are used, until context expires.

func (*SyncClient) CancelTask

func (sc *SyncClient) CancelTask(
	ctx context.Context,
	logger log.Logger,
	id uuid.UUID,
) error

cancel a running task NOTE: the server treats this as a hint and does not report a return status and may ignore it, the error return value only covers if the server received and acknowledged the request

func (*SyncClient) ClientAlive

func (sc *SyncClient) ClientAlive(
	ctx context.Context,
	logger log.Logger,
	timeout time.Duration,
	tries int,
) (bool, error)

Check if server responds to echo commands, the timeout is per try

func (*SyncClient) Close

func (sc *SyncClient) Close() error

close all listeners and underlying client

func (*SyncClient) CreateSession

func (sc *SyncClient) CreateSession(
	ctx context.Context,
	logger log.Logger,
	args *isalink.SessionStartArgs,
) (uuid.UUID, error)

create a new session, returns the used ID expected another goroutine to handle ticking

func (*SyncClient) Deregister

func (sc *SyncClient) Deregister(id uuid.UUID) error

deregister a listener

func (*SyncClient) ListSessions

func (sc *SyncClient) ListSessions(
	ctx context.Context,
	logger log.Logger,
) ([]uuid.UUID, error)

func (*SyncClient) PendingListeners

func (sc *SyncClient) PendingListeners() int

return number of pending listeners, intended for tests

func (*SyncClient) PurgeTheories

func (sc *SyncClient) PurgeTheories(
	ctx context.Context,
	logger log.Logger,
	args *isalink.PurgeTheoriesArgs,
) ([]any, []any, error)

Purge theories from a session, returns (purged, retains, error) retained and purged may be errors

func (*SyncClient) Reconnect

func (sc *SyncClient) Reconnect(
	ctx context.Context,
	logger log.Logger,
	password []byte,
	validateResponse bool,
) error

close listeners and try to reconnect internal client

func (*SyncClient) Send

func (sc *SyncClient) Send(msg *isalink.ServerMessage)

push message into listeners

func (*SyncClient) Shutdown

func (sc *SyncClient) Shutdown(ctx context.Context, logger log.Logger) error

issue a shutdown

func (*SyncClient) State

func (sc *SyncClient) State() isalink.IsaClientState

retrieve client state, NOTE: this requires holding the write lock, only use for debugging

func (*SyncClient) StopSession

func (sc *SyncClient) StopSession(
	ctx context.Context,
	logger log.Logger,
	sessionID uuid.UUID,
) error

func (*SyncClient) SyncCommand

func (sc *SyncClient) SyncCommand(
	ctx context.Context,
	logger log.Logger,
	msg *isalink.ClientMessage,
) (*isalink.ServerMessage, error)

Send asynchronous command and return next non-matched message from server

func (*SyncClient) TestMode

func (sc *SyncClient) TestMode()

enable test mode for underlying isalink.IsaClient

func (*SyncClient) Ticker

func (sc *SyncClient) Ticker(ctx context.Context, logger log.Logger) error

continuously process incoming messages in the background. This will block until an error occurs or the ctx is terminated, will close client on exit

func (*SyncClient) Ticking

func (sc *SyncClient) Ticking() bool

is a ticker running?

func (*SyncClient) UseTheories

func (sc *SyncClient) UseTheories(
	ctx context.Context,
	logger log.Logger,
	args *isalink.UseTheoriesArguments,
) ([]*isalink.ServerMessage, error)

dispatch a use_theories call

func (*SyncClient) WaitTask

func (sc *SyncClient) WaitTask(
	ctx context.Context, logger log.Logger,
	aggregate bool,
	id uuid.UUID,
	msgChan <-chan *isalink.ServerMessage,
) ([]*isalink.ServerMessage, error)

await task by (id, chan) and deregister listener afterwards

Source Files

  • client-commands.go
  • client.go

Jump to

Keyboard shortcuts

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