https://github.com/damnever/goqueue
See https://github.com/damnever/goctl
https://github.com/damnever/goqueue
golang goroutine-safe queue
Last synced: 5 months ago
JSON representation
See https://github.com/damnever/goctl
- Host: GitHub
- URL: https://github.com/damnever/goqueue
- Owner: damnever
- License: other
- Archived: true
- Created: 2015-12-09T14:01:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T14:45:39.000Z (over 7 years ago)
- Last Synced: 2025-08-14T10:00:10.329Z (10 months ago)
- Topics: golang, goroutine-safe, queue
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 47
- Watchers: 6
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## A GoRoutine safe queue for Golang [](https://travis-ci.org/damnever/goqueue) [](https://godoc.org/github.com/damnever/goqueue)
It is similar to the Queue of Python.
### Installation
```
go get github.com/damnever/goqueue
```
### Example
Just for example, I use `Queue.Get(0)` and `Queue.PutNoWait(value)` more and often, but channel is not a right way do that...
```Go
package main
import (
"fmt"
"sync"
"github.com/Damnever/goqueue"
)
func main() {
queue := goqueue.New(0)
wg := &sync.WaitGroup{}
worker := func(queue *goqueue.Queue) {
defer wg.Done()
for !queue.IsEmpty() {
val, err := queue.Get(0)
if err != nil {
fmt.Println("Unexpect Error: %v\n", err)
}
num := val.(int)
fmt.Printf("-> %v\n", num)
if num%3 == 0 {
for i := num + 1; i < num+3; i++ {
queue.PutNoWait(i)
}
}
}
}
go func() {
defer wg.Done()
for i := 0; i <= 27; i += 3 {
queue.PutNoWait(i)
}
}()
for i := 0; i < 5; i++ {
go worker(queue)
}
wg.Add(6)
wg.Wait()
fmt.Println("All task done!!!")
}
```