https://github.com/sheerun/queue
Lightweight, thread-safe, blocking FIFO queue based on auto-resizing circular buffer
https://github.com/sheerun/queue
golang queues thread-safe
Last synced: 10 months ago
JSON representation
Lightweight, thread-safe, blocking FIFO queue based on auto-resizing circular buffer
- Host: GitHub
- URL: https://github.com/sheerun/queue
- Owner: sheerun
- Created: 2018-01-07T17:01:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-18T11:34:56.000Z (about 5 years ago)
- Last Synced: 2025-03-19T07:37:38.345Z (10 months ago)
- Topics: golang, queues, thread-safe
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 70
- Watchers: 5
- Forks: 26
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Queue
[](https://godoc.org/github.com/sheerun/queue)
[](https://github.com/sheerun/queue/releases/latest)
[](LICENSE.txt)
Lightweight, tested, performant, thread-safe, blocking FIFO queue based on auto-resizing circular buffer.
## Usage
```go
package main
import (
"fmt"
"sync"
"time"
"github.com/sheerun/queue"
)
func main() {
q := queue.New()
var wg sync.WaitGroup
wg.Add(2)
// Worker 1
go func() {
for i := 0; i < 500; i++ {
item := q.Pop()
fmt.Printf("%v\n", item)
time.Sleep(10 * time.Millisecond)
}
wg.Done()
}()
// Worker 2
go func() {
for i := 0; i < 500; i++ {
item := q.Pop()
fmt.Printf("%v\n", item)
time.Sleep(10 * time.Millisecond)
}
wg.Done()
}()
for i := 0; i < 1000; i++ {
q.Append(i)
}
wg.Wait()
}
```
## License
MIT