Documentation ¶
Index ¶
- Variables
- type DQue
- func New(name string, dirPath string, itemsPerSegment int, builder func() interface{}) (*DQue, error)
- func NewOrOpen(name string, dirPath string, itemsPerSegment int, builder func() interface{}) (*DQue, error)
- func Open(name string, dirPath string, itemsPerSegment int, builder func() interface{}) (*DQue, error)
- func (q *DQue) Close() error
- func (q *DQue) Dequeue() (interface{}, error)
- func (q *DQue) DequeueBlock() (interface{}, error)
- func (q *DQue) Enqueue(obj interface{}) error
- func (q *DQue) Peek() (interface{}, error)
- func (q *DQue) PeekBlock() (interface{}, error)
- func (q *DQue) SegmentNumbers() (int, int)
- func (q *DQue) Size() int
- func (q *DQue) SizeUnsafe() int
- func (q *DQue) Turbo() bool
- func (q *DQue) TurboOff() error
- func (q *DQue) TurboOn() error
- func (q *DQue) TurboSync() error
- type ErrCorruptedSegment
- type ErrUnableToDecode
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmpty is returned when attempting to dequeue from an empty queue. ErrEmpty = errors.New("dque is empty") )
var ErrQueueClosed = errors.New("queue is closed")
ErrQueueClosed is the error returned when a queue is closed.
Functions ¶
This section is empty.
Types ¶
type DQue ¶
DQue is the in-memory representation of a queue on disk. You must never have two *active* DQue instances pointing at the same path on disk. It is acceptable to reconstitute a new instance from disk, but make sure the old instance is never enqueued to (or dequeued from) again.
func New ¶
func New(name string, dirPath string, itemsPerSegment int, builder func() interface{}) (*DQue, error)
New creates a new durable queue
func NewOrOpen ¶
func NewOrOpen(name string, dirPath string, itemsPerSegment int, builder func() interface{}) (*DQue, error)
NewOrOpen either creates a new queue or opens an existing durable queue.
func Open ¶
func Open(name string, dirPath string, itemsPerSegment int, builder func() interface{}) (*DQue, error)
Open opens an existing durable queue.
func (*DQue) Close ¶
Close releases the lock on the queue rendering it unusable for further usage by this instance. Close will return an error if it has already been called.
func (*DQue) Dequeue ¶
Dequeue removes and returns the first item in the queue. When the queue is empty, nil and dque.ErrEmpty are returned.
func (*DQue) DequeueBlock ¶
DequeueBlock behaves similar to Dequeue, but is a blocking call until an item is available.
func (*DQue) Peek ¶
Peek returns the first item in the queue without dequeueing it. When the queue is empty, nil and dque.ErrEmpty are returned. Do not use this method with multiple dequeueing threads or you may regret it.
func (*DQue) PeekBlock ¶
PeekBlock behaves similar to Peek, but is a blocking call until an item is available.
func (*DQue) SegmentNumbers ¶
SegmentNumbers returns the number of both the first last segmment. There is likely no use for this information other than testing.
func (*DQue) Size ¶
Size locks things up while calculating so you are guaranteed an accurate size... unless you have changed the itemsPerSegment value since the queue was last empty. Then it could be wildly inaccurate.
func (*DQue) SizeUnsafe ¶
SizeUnsafe returns the approximate number of items in the queue. Use Size() if having the exact size is important to your use-case.
The return value could be wildly inaccurate if the itemsPerSegment value has changed since the queue was last empty. Also, because this method is not synchronized, the size may change after entering this method.
func (*DQue) Turbo ¶
Turbo returns true if the turbo flag is on. Having turbo on speeds things up significantly.
func (*DQue) TurboOff ¶
TurboOff re-enables the "safety" mode that syncs every file change to disk as they happen. If turbo is already off an error is returned
type ErrCorruptedSegment ¶
ErrCorruptedSegment is returned when a segment file cannot be opened due to inconsistent formatting. Recovery may be possible by clearing or deleting the file, then reloading using dque.New().
func (ErrCorruptedSegment) Error ¶
func (e ErrCorruptedSegment) Error() string
Error returns a string describing ErrCorruptedSegment
func (ErrCorruptedSegment) Unwrap ¶
func (e ErrCorruptedSegment) Unwrap() error
Unwrap returns the wrapped error
type ErrUnableToDecode ¶
ErrUnableToDecode is returned when an object cannot be decoded.
func (ErrUnableToDecode) Error ¶
func (e ErrUnableToDecode) Error() string
Error returns a string describing ErrUnableToDecode error
func (ErrUnableToDecode) Unwrap ¶
func (e ErrUnableToDecode) Unwrap() error
Unwrap returns the wrapped error