Documentation ¶
Index ¶
- Constants
- type Job
- type JobAction
- type JobQueue
- func (q *JobQueue[K]) Acquire() (w Job[K], shouldAcquireMore bool)
- func (q *JobQueue[K]) Find(key K) (Job[K], bool)
- func (q *JobQueue[K]) Offer(w Job[K]) error
- func (q *JobQueue[K]) Pause()
- func (q *JobQueue[K]) Remains() []Job[K]
- func (q *JobQueue[K]) Remove(w Job[K]) bool
- func (q *JobQueue[K]) Resume()
- type SeqDataHandleFunc
- type SeqQueue
- type TimeoutData
- type TimeoutQueue
- func (q *TimeoutQueue[K, V]) Allow(key K)
- func (q *TimeoutQueue[K, V]) Clear()
- func (q *TimeoutQueue[K, V]) Find(key K) (_ V, _ bool)
- func (q *TimeoutQueue[K, V]) Forbid(key K)
- func (q *TimeoutQueue[K, V]) Len() int
- func (q *TimeoutQueue[K, V]) Less(i, j int) bool
- func (q *TimeoutQueue[K, V]) OfferWithDelay(key K, val V, wait time.Duration) error
- func (q *TimeoutQueue[K, V]) OfferWithTime(key K, val V, at time.Time) error
- func (q *TimeoutQueue[K, V]) Remains() []TimeoutData[K, V]
- func (q *TimeoutQueue[K, V]) Remove(key K) (ret V, _ bool)
- func (q *TimeoutQueue[K, V]) Start(stop <-chan struct{})
- func (q *TimeoutQueue[K, V]) Swap(i, j int)
- func (q *TimeoutQueue[K, V]) TakeCh() <-chan *TimeoutData[K, V]
Constants ¶
const ( ErrJobDuplicated errhelper.ErrString = "job duplicat" ErrJobConflict errhelper.ErrString = "job conflict" ErrJobCounteract errhelper.ErrString = "job counteract" ErrJobInvalid errhelper.ErrString = "job invalid" )
Errors for JobQueue
const ( ErrNotStarted errhelper.ErrString = "not started" ErrStopped errhelper.ErrString = "stopped" ErrKeyNotAllowed errhelper.ErrString = "key not allowed" )
Errors for timeout queue
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job[K comparable] struct { Action JobAction Key K }
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[K comparable] 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[K comparable]() *JobQueue[K]
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[K]) Acquire ¶
Acquire a job item from the job queue if shouldAcquireMore is false, w will be an empty job
func (*JobQueue[K]) Offer ¶
Offer a job item to the job queue if offered job was not added, an error result will return, otherwise nil
func (*JobQueue[K]) Pause ¶
func (q *JobQueue[K]) 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 SeqQueue ¶
type SeqQueue[T any] struct { // contains filtered or unexported fields }
SeqQueue is the sequence queue for unordered data
func NewSeqQueue ¶
func NewSeqQueue[T any](handleData SeqDataHandleFunc[T]) *SeqQueue[T]
NewSeqQueue returns a empty SeqQueue
type TimeoutData ¶
type TimeoutData[K comparable, V any] struct { Key K Data V // contains filtered or unexported fields }
TimeoutData is the data set used internally
type TimeoutQueue ¶
type TimeoutQueue[K comparable, V any] 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[K comparable, V any]() *TimeoutQueue[K, V]
NewTimeoutQueue returns an idle TimeoutQueue
func (*TimeoutQueue[K, V]) Allow ¶
func (q *TimeoutQueue[K, V]) Allow(key K)
Allow allow tasks with key, future tasks with the key can be offered
func (*TimeoutQueue[K, V]) Clear ¶
func (q *TimeoutQueue[K, V]) Clear()
Clear out all timeout key-value pairs
func (*TimeoutQueue[K, V]) Find ¶
func (q *TimeoutQueue[K, V]) Find(key K) (_ V, _ bool)
Find timeout key-value pair according to the key
func (*TimeoutQueue[K, V]) Forbid ¶
func (q *TimeoutQueue[K, V]) Forbid(key K)
Forbid forbid tasks with key, future tasks with the key cannot be offered
func (*TimeoutQueue[K, V]) Len ¶
func (q *TimeoutQueue[K, V]) Len() int
Len is used internally for timeout data sort
func (*TimeoutQueue[K, V]) Less ¶
func (q *TimeoutQueue[K, V]) Less(i, j int) bool
Less is used internally for timeout data sort
func (*TimeoutQueue[K, V]) OfferWithDelay ¶
func (q *TimeoutQueue[K, V]) OfferWithDelay(key K, val V, 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[K, V]) OfferWithTime ¶
func (q *TimeoutQueue[K, V]) OfferWithTime(key K, val V, 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[K, V]) Remains ¶
func (q *TimeoutQueue[K, V]) Remains() []TimeoutData[K, V]
Remains shows key-value pairs not timed out
func (*TimeoutQueue[K, V]) Remove ¶
func (q *TimeoutQueue[K, V]) Remove(key K) (ret V, _ bool)
Remove a timeout object from the queue according to the key
func (*TimeoutQueue[K, V]) Start ¶
func (q *TimeoutQueue[K, V]) Start(stop <-chan struct{})
Start routine to generate timeout data
func (*TimeoutQueue[K, V]) Swap ¶
func (q *TimeoutQueue[K, V]) Swap(i, j int)
Swap is used internally for timeout data sort
func (*TimeoutQueue[K, V]) TakeCh ¶
func (q *TimeoutQueue[K, V]) TakeCh() <-chan *TimeoutData[K, V]
TakeCh returns the channel from which you can get key-value pairs timed out one by one