Documentation ¶
Index ¶
- Variables
- type Job
- type JobAction
- type JobQueue
- type SeqDataHandleFunc
- type SeqQueue
- type TimeoutData
- type TimeoutQueue
- func (q *TimeoutQueue) Allow(key interface{})
- func (q *TimeoutQueue) Clear()
- func (q *TimeoutQueue) Find(key interface{}) (interface{}, bool)
- func (q *TimeoutQueue) Forbid(key interface{})
- func (q *TimeoutQueue) Len() int
- func (q *TimeoutQueue) Less(i, j int) bool
- func (q *TimeoutQueue) OfferWithDelay(key, val interface{}, wait time.Duration) error
- func (q *TimeoutQueue) OfferWithTime(key, val interface{}, at time.Time) error
- func (q *TimeoutQueue) Remains() []TimeoutData
- func (q *TimeoutQueue) Remove(key interface{}) (interface{}, bool)
- func (q *TimeoutQueue) Start(stop <-chan struct{})
- func (q *TimeoutQueue) Swap(i, j int)
- func (q *TimeoutQueue) TakeCh() <-chan *TimeoutData
Constants ¶
This section is empty.
Variables ¶
var ( ErrJobDuplicated = errors.New("job duplicat") ErrJobConflict = errors.New("job conflict") ErrJobCounteract = errors.New("job counteract") ErrJobInvalid = errors.New("job invalid") )
Errors for JobQueue
var ( ErrNotStarted = errors.New("not started") ErrStopped = errors.New("stopped") ErrKeyNotAllowed = errors.New("key not allowed") )
Errors for timeout queue
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct { Action JobAction Key interface{} }
Job item to record action and related resource object
type JobAction ¶
type JobAction uint8
const ( // ActionInvalid to do nothing ActionInvalid JobAction = iota // ActionAdd to add or create some resource ActionAdd // ActionUpdate to update some resource ActionUpdate // ActionDelete to delete some resource ActionDelete // ActionCleanup to eliminate all side effects of the resource ActionCleanup )
type JobQueue ¶
type JobQueue struct {
// contains filtered or unexported fields
}
JobQueue is the queue data structure designed to reduce redundant job as much as possible
func NewJobQueue ¶
func NewJobQueue() *JobQueue
NewJobQueue will create a stopped new job queue, you can offer job to it, but any acquire will fail until you have called its Resume()
func (*JobQueue) Acquire ¶
Acquire a job item from the job queue if shouldAcquireMore is false, w will be an empty job
func (*JobQueue) Offer ¶
Offer a job item to the job queue if offered job was not added, an error result will return, otherwise nil
func (*JobQueue) Pause ¶
func (q *JobQueue) Pause()
Pause do nothing but mark this job queue is closed, you should not perform acquire actions to the job queue
type SeqDataHandleFunc ¶ added in v0.5.4
type SeqDataHandleFunc func(seq uint64, d interface{})
type SeqQueue ¶
type SeqQueue struct {
// contains filtered or unexported fields
}
SeqQueue is the sequence queue for unordered data
func NewSeqQueue ¶
func NewSeqQueue(handleData SeqDataHandleFunc) *SeqQueue
NewSeqQueue returns a empty SeqQueue
type TimeoutData ¶
type TimeoutData struct { Key interface{} Data interface{} // contains filtered or unexported fields }
TimeoutData is the data set used internally
type TimeoutQueue ¶
type TimeoutQueue struct {
// contains filtered or unexported fields
}
TimeoutQueue to arrange timeout events in a single queue, then you can access them in sequence with channel
func NewTimeoutQueue ¶
func NewTimeoutQueue() *TimeoutQueue
NewTimeoutQueue returns an idle TimeoutQueue
func (*TimeoutQueue) Allow ¶
func (q *TimeoutQueue) Allow(key interface{})
Allow allow tasks with key, future tasks with the key can be offered
func (*TimeoutQueue) Find ¶
func (q *TimeoutQueue) Find(key interface{}) (interface{}, bool)
Find timeout key-value pair according to the key
func (*TimeoutQueue) Forbid ¶
func (q *TimeoutQueue) Forbid(key interface{})
Forbid forbid tasks with key, future tasks with the key cannot be offered
func (*TimeoutQueue) Len ¶
func (q *TimeoutQueue) Len() int
Len is used internally for timeout data sort
func (*TimeoutQueue) Less ¶
func (q *TimeoutQueue) Less(i, j int) bool
Less is used internally for timeout data sort
func (*TimeoutQueue) OfferWithDelay ¶
func (q *TimeoutQueue) OfferWithDelay(key, val interface{}, wait time.Duration) error
OfferWithDelay to enqueue key-value pair, timeout after `wait`, if you would like to call Remove to delete the timeout object, `key` must be unique in this queue
func (*TimeoutQueue) OfferWithTime ¶
func (q *TimeoutQueue) OfferWithTime(key, val interface{}, at time.Time) error
OfferWithTime to enqueue key-value pair with time, timeout at `time`, if you would like to call Remove to delete the timeout object, `key` must be unique in this queue
func (*TimeoutQueue) Remains ¶
func (q *TimeoutQueue) Remains() []TimeoutData
Remains shows key-value pairs not timed out
func (*TimeoutQueue) Remove ¶
func (q *TimeoutQueue) Remove(key interface{}) (interface{}, bool)
Remove a timeout object from the queue according to the key
func (*TimeoutQueue) Start ¶
func (q *TimeoutQueue) Start(stop <-chan struct{})
Start routine to generate timeout data
func (*TimeoutQueue) Swap ¶
func (q *TimeoutQueue) Swap(i, j int)
Swap is used internally for timeout data sort
func (*TimeoutQueue) TakeCh ¶
func (q *TimeoutQueue) TakeCh() <-chan *TimeoutData
TakeCh returns the channel from which you can get key-value pairs timed out one by one