registry

package
v0.0.0-...-23dbee4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultNamespace is the default namespace for watchers.
	DefaultNamespace = "w"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LoggingWatcher

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

LoggingWatcher is a wrapper around a worker.Worker that logs when it finishes.

func NewLoggingWatcher

func NewLoggingWatcher(w worker.Worker, logger logger.Logger) *LoggingWatcher

NewLoggingWatcher returns a new LoggingWatcher that wraps the given worker, so we can log when it starts and finishes.

func (*LoggingWatcher) Kill

func (l *LoggingWatcher) Kill()

Kill asks the worker to stop and returns immediately.

func (*LoggingWatcher) Unwrap

func (l *LoggingWatcher) Unwrap() worker.Worker

Unwrap returns the wrapped worker.

func (*LoggingWatcher) Wait

func (l *LoggingWatcher) Wait() error

Wait waits for the worker to complete and returns any error encountered when it was running or stopping.

type Option

type Option func(*option)

Option defines a function for setting options on a Registry.

func WithLogger

func WithLogger(logger logger.Logger) Option

WithLogger returns an Option that sets the logger to use for logging when workers finish.

type Registry

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

Registry holds all the watchers for a connection. It allows the registration of watchers that will be cleaned up when a connection terminates.

func NewRegistry

func NewRegistry(clock clock.Clock, opts ...Option) (*Registry, error)

NewRegistry returns a new Registry that also starts a worker to manage the registry.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of resources currently held.

func (*Registry) Get

func (r *Registry) Get(id string) (worker.Worker, error)

Get returns the watcher for the given id, or nil if there is no such watcher.

func (*Registry) Kill

func (r *Registry) Kill()

Kill implements the worker.Worker interface.

func (*Registry) Register

func (r *Registry) Register(w worker.Worker) (string, error)

Register registers the given watcher. It returns a unique identifier for the watcher which can then be used in subsequent API requests to refer to the watcher.

func (*Registry) RegisterNamed

func (r *Registry) RegisterNamed(namespace string, w worker.Worker) error

RegisterNamed registers the given watcher. Callers must supply a unique name for the given watcher. It is an error to try to register another watcher with the same name as an already registered name. It is also an error to supply a name that is an integer string, since that collides with the auto-naming from Register.

func (*Registry) Stop

func (r *Registry) Stop(id string) error

Stop stops the resource with the given id and unregisters it. It returns any error from the underlying Stop call. It does not return an error if the resource has already been unregistered.

func (*Registry) Wait

func (r *Registry) Wait() error

Wait implements the worker.Worker interface.

Jump to

Keyboard shortcuts

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