Documentation ¶
Overview ¶
Package mpsc provides an efficient implementation of a multi-producer, single-consumer lock-free queue.
The Push function is safe to call from multiple goroutines. The Pop and Empty APIs must only be called from a single, consumer goroutine.
Index ¶
- Variables
- type Queue
- type StartFn
- type StopFn
- type Task
- type TaskHandler
- type Tasker
- func (t *Tasker) Add(ctx context.Context, f TaskHandler, p ...interface{})
- func (t *Tasker) AddWait(ctx context.Context, f TaskHandler, p ...interface{}) error
- func (t *Tasker) GetTaskNum() int
- func (t *Tasker) Init(opts ...TaskerOption)
- func (t *Tasker) IsRunning() bool
- func (t *Tasker) ResetTimer()
- func (t *Tasker) Run(ctx context.Context) (reterr error)
- func (t *Tasker) Stop()
- type TaskerOption
- func WithExecuteTimeout(d time.Duration) TaskerOption
- func WithOutput(output io.Writer) TaskerOption
- func WithStartFns(f ...StartFn) TaskerOption
- func WithStopFns(f ...StopFn) TaskerOption
- func WithTimeout(d time.Duration) TaskerOption
- func WithUniqueId(id int32) TaskerOption
- func WithUpdateFn(f UpdateFn) TaskerOption
- func WithUpdateInterval(d time.Duration) TaskerOption
- type TaskerOptions
- type UpdateFn
Constants ¶
This section is empty.
Variables ¶
View Source
var ( TaskDefaultExecuteTimeout = time.Second * 5 // execute timeout TaskDefaultTimeout = time.Hour * 24 * 356 // default timeout TaskDefaultUpdateInterval = time.Second // update interval ErrTimeout = errors.New("time out") ErrTaskPanic = errors.New("task panic") ErrTaskFailed = errors.New("task failed") ErrTaskFulled = errors.New("task fulled") ErrTaskNotRunning = errors.New("task not running") )
Functions ¶
This section is empty.
Types ¶
type Queue ¶ added in v1.3.5
type Queue struct {
// contains filtered or unexported fields
}
func (*Queue) Empty ¶ added in v1.3.5
Empty returns true if the queue is empty
Empty must be called from a single, consumer goroutine
func (*Queue) Pop ¶ added in v1.3.5
func (q *Queue) Pop() interface{}
Pop removes the item from the front of the queue or nil if the queue is empty
Pop must be called from a single, consumer goroutine
type TaskHandler ¶
type Tasker ¶
type Tasker struct {
// contains filtered or unexported fields
}
func (*Tasker) AddWait ¶ added in v1.0.6
func (t *Tasker) AddWait(ctx context.Context, f TaskHandler, p ...interface{}) error
func (*Tasker) GetTaskNum ¶ added in v1.2.2
func (*Tasker) Init ¶
func (t *Tasker) Init(opts ...TaskerOption)
func (*Tasker) ResetTimer ¶
func (t *Tasker) ResetTimer()
type TaskerOption ¶
type TaskerOption func(*TaskerOptions)
func WithExecuteTimeout ¶ added in v1.1.8
func WithExecuteTimeout(d time.Duration) TaskerOption
func WithOutput ¶ added in v1.2.8
func WithOutput(output io.Writer) TaskerOption
func WithStartFns ¶ added in v1.0.3
func WithStartFns(f ...StartFn) TaskerOption
func WithStopFns ¶ added in v1.1.1
func WithStopFns(f ...StopFn) TaskerOption
func WithTimeout ¶
func WithTimeout(d time.Duration) TaskerOption
func WithUniqueId ¶ added in v1.2.2
func WithUniqueId(id int32) TaskerOption
func WithUpdateFn ¶ added in v1.0.2
func WithUpdateFn(f UpdateFn) TaskerOption
func WithUpdateInterval ¶ added in v1.1.7
func WithUpdateInterval(d time.Duration) TaskerOption
type TaskerOptions ¶
type TaskerOptions struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.