worker

package
v1.0.0-b001 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultQueueWorkerMaxWork is the maximum number of work items before queueing blocks.
	DefaultQueueWorkerMaxWork = 1 << 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Interval

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

Interval is a managed goroutine that does things.

func NewInterval

func NewInterval(action func() error, interval time.Duration) *Interval

NewInterval returns a new worker that runs an action on an interval.

func (*Interval) Action

func (i *Interval) Action() func() error

Action returns the interval action.

func (*Interval) Delay

func (i *Interval) Delay() time.Duration

Delay returns the start delay.

func (*Interval) Errors

func (i *Interval) Errors() chan error

Errors returns a channel to read action errors from.

func (Interval) Interval

func (i Interval) Interval() time.Duration

Interval returns the interval for the ticker.

func (*Interval) Latch

func (i *Interval) Latch() *Latch

Latch returns the inteval worker latch.

func (*Interval) Start

func (i *Interval) Start()

Start starts the worker.

func (*Interval) Stop

func (i *Interval) Stop()

Stop stops the worker.

func (*Interval) WithAction

func (i *Interval) WithAction(action func() error) *Interval

WithAction sets the interval action.

func (*Interval) WithDelay

func (i *Interval) WithDelay(d time.Duration) *Interval

WithDelay sets a start delay time.

func (*Interval) WithErrors

func (i *Interval) WithErrors(errors chan error) *Interval

WithErrors returns the error channel.

type Latch

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

Latch is a helper to coordinate killing goroutines. The lifecycle is generally as follows. 0 - stopped 1 - signal started 2 - running / started N-2 - signal stop N-1 - stopping goto 0

func (*Latch) IsRunning

func (l *Latch) IsRunning() bool

IsRunning indicates we can signal to stop.

func (*Latch) IsStarting

func (l *Latch) IsStarting() bool

IsStarting indicates the latch is waiting to be scheduled.

func (*Latch) IsStopped

func (l *Latch) IsStopped() bool

IsStopped returns if the latch is stopped.

func (*Latch) IsStopping

func (l *Latch) IsStopping() bool

IsStopping returns if the latch is waiting to finish stopping.

func (*Latch) NotifyStarted

func (l *Latch) NotifyStarted() <-chan struct{}

NotifyStarted returns the started signal. It is used to coordinate the transition from starting -> started.

func (*Latch) NotifyStop

func (l *Latch) NotifyStop() <-chan struct{}

NotifyStop returns the should stop signal. It is used to trigger the transition from running -> stopping -> stopped.

func (*Latch) NotifyStopped

func (l *Latch) NotifyStopped() <-chan struct{}

NotifyStopped returns the stopped signal. It is used to coordinate the transition from stopping -> stopped.

func (*Latch) Started

func (l *Latch) Started()

Started signals that the latch is started and has entered the `IsRunning` state.

func (*Latch) Starting

func (l *Latch) Starting()

Starting signals the latch is starting. This is typically done before you kick off a goroutine.

func (*Latch) Stop

func (l *Latch) Stop()

Stop signals the latch to stop. It could also be thought of as `SignalStopping`.

func (*Latch) Stopped

func (l *Latch) Stopped()

Stopped signals the latch has stopped.

type QueueWorker

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

QueueWorker is a worker that is pushed work over a channel.

func NewQueue

func NewQueue(action func(interface{}) error) *QueueWorker

NewQueue returns a new queue worker.

func (*QueueWorker) Enqueue

func (qw *QueueWorker) Enqueue(obj interface{})

Enqueue adds an item to the work queue.

func (*QueueWorker) ErrorCollector

func (qw *QueueWorker) ErrorCollector() chan error

ErrorCollector returns a channel to read action errors from.

func (*QueueWorker) Latch

func (qw *QueueWorker) Latch() *Latch

Latch returns the worker latch.

func (*QueueWorker) MaxWork

func (qw *QueueWorker) MaxWork() int

MaxWork returns the maximum work.

func (*QueueWorker) Start

func (qw *QueueWorker) Start()

Start starts the worker.

func (*QueueWorker) Stop

func (qw *QueueWorker) Stop()

Stop stops the worker.

func (*QueueWorker) WithErrorCollector

func (qw *QueueWorker) WithErrorCollector(errors chan error) *QueueWorker

WithErrorCollector returns the error channel.

func (*QueueWorker) WithMaxWork

func (qw *QueueWorker) WithMaxWork(maxWork int) *QueueWorker

WithMaxWork sets the worker max work.

Jump to

Keyboard shortcuts

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