Documentation ¶
Index ¶
- Constants
- type LoggingWatcher
- type Option
- type Registry
- func (r *Registry) Count() int
- func (r *Registry) Get(id string) (worker.Worker, error)
- func (r *Registry) Kill()
- func (r *Registry) Register(w worker.Worker) (string, error)
- func (r *Registry) RegisterNamed(namespace string, w worker.Worker) error
- func (r *Registry) Stop(id string) error
- func (r *Registry) Wait() error
Constants ¶
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 ¶
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 ¶
NewRegistry returns a new Registry that also starts a worker to manage the registry.
func (*Registry) Get ¶
Get returns the watcher for the given id, or nil if there is no such watcher.
func (*Registry) Register ¶
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 ¶
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.