Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultQueueCapacity is the default capacity of local cache. // The specified capacity should not be less than it. DefaultQueueCapacity = 8 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface {
// GetQueue creates a new Queue instance for a goroutine.
//
// For example:
//
// func consuming(q Queue) {
// for v := q.Dequeue() {
// ...
// }
// }
//
// func producing(q Queue) {
// for i:=0; i<100; i++ {
// q.Enqueue(i)
// }
// q.Flush() // flushes the left caching values
// }
//
// func main() {
// b := NewBatch()
// go consuming(b.GetQueue())
// go producing(b.GetQueue())
// ...
// }
GetQueue() Queue
}
A Batch is an in-memory concurrency-safe message queue with local cache.
type Queue ¶
type Queue interface {
// Enqueue pushes a value to local cache. When the local cache
// is full, it'll be commited to the batchqueue.
Enqueue(v interface{})
// Dequeue pops a value from local cache. When the local cache
// is empty, it gets one local cache from batchqueue.
Dequeue() (v interface{})
// Flush forcely commits local cache to the batchqueue.
Flush()
}
A Queue is a message queue with local cache. When its local cache is not full, it won't commit the caching values to the batchqueue. Or it can forcely commit the caching values by Flush.
A Queue must be used by only one goroutine, because it enqueues or dequeues a value without locking.
Using local cache for less locking.
Click to show internal directories.
Click to hide internal directories.