https://github.com/fireflycons/concurrentqueue
Package queue implements a mutex-free channel-based queue.
https://github.com/fireflycons/concurrentqueue
Last synced: 6 months ago
JSON representation
Package queue implements a mutex-free channel-based queue.
- Host: GitHub
- URL: https://github.com/fireflycons/concurrentqueue
- Owner: fireflycons
- License: mit
- Created: 2026-01-09T06:25:53.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2026-01-12T12:39:34.000Z (6 months ago)
- Last Synced: 2026-01-12T19:45:41.040Z (6 months ago)
- Language: Go
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# queue
[](https://pkg.go.dev/github.com/fireflycons/concurrentqueue) [](https://github.com/fireflycons/concurrentqueue/actions/workflows/build.yml) [](https://goreportcard.com/report/github.com/fireflycons/concurrentqueue)
Package queue implements a mutex\-free channel\-based generic queue. It is not designed for raw speed, but rather to be used as a data source for things like worker pools where reading input from a channel makes sense.
The queue is backed by a ring buffer with a default initial capacity of 256 elements that grows as needed. A constructor method is provided to set the initial capacity if desired.
Where locking is required, it is done at the ring buffer level using spinlocks to minimize contention.
## Features
* Dependency free
* Mutex free
* Concurrent
* Generic
* Channel based implementation
* Backed by a ringbuffer for reduced allocs
* Used by my [workerpool](https://pkg.go.dev/github.com/fireflycons/workerpool) implementation
## Example
```go
package main
import (
"fmt"
queue "github.com/fireflycons/concurrentqueue"
)
func main() {
q := queue.New[int]()
for i := range 10 {
_ = q.Enqueue(i)
}
// Close the queue to signal no more elements will be added
q.Close()
// Dequeue is a channel, therefore it would block until elements are available
// or the queue is closed and emptied.
for v := range q.Dequeue() {
fmt.Println(v)
}
}
```