-
Notifications
You must be signed in to change notification settings - Fork 32
/
queue.go
29 lines (26 loc) · 1.19 KB
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package goconcurrentqueue
import "context"
// Queue interface with basic && common queue functions
type Queue interface {
// Enqueue element
Enqueue(interface{}) error
// Dequeue element
Dequeue() (interface{}, error)
// DequeueOrWaitForNextElement dequeues an element (if exist) or waits until the next element gets enqueued and returns it.
// Multiple calls to DequeueOrWaitForNextElement() would enqueue multiple "listeners" for future enqueued elements.
DequeueOrWaitForNextElement() (interface{}, error)
// DequeueOrWaitForNextElementContext dequeues an element (if exist) or waits until the next element gets enqueued and returns it.
// Multiple calls to DequeueOrWaitForNextElementContext() would enqueue multiple "listeners" for future enqueued elements.
// When the passed context expires this function exits and returns the context' error
DequeueOrWaitForNextElementContext(context.Context) (interface{}, error)
// Get number of enqueued elements
GetLen() int
// Get queue's capacity
GetCap() int
// Lock the queue. No enqueue/dequeue/remove/get operations will be allowed after this point.
Lock()
// Unlock the queue.
Unlock()
// Return true whether the queue is locked
IsLocked() bool
}