Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxcnunes/go-queue
A modest implementation of queue in go
https://github.com/maxcnunes/go-queue
Last synced: about 2 months ago
JSON representation
A modest implementation of queue in go
- Host: GitHub
- URL: https://github.com/maxcnunes/go-queue
- Owner: maxcnunes
- Created: 2016-06-13T01:20:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-13T11:14:29.000Z (over 8 years ago)
- Last Synced: 2024-10-18T07:21:16.449Z (3 months ago)
- Language: Go
- Homepage:
- Size: 1000 Bytes
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
go-queue
========A modest implementation of queue in go. The main advantage of this queue is that it allows running tasks concurrently.
## Usage
```go
import "github.com/maxcnunes/go-queue"const CONCURRENT = 10
type TaskRunner struct {
// include any context data
}func (t TaskRunner) Run(item interface{}) error {
// data := item.(YOUR_DATA_TYPE)
}func main() {
q := goqueue.NewQueue(
CONCURRENT,
MergeCardBranchesTaskRunner{},
).Run()// seed the queue
go loadJobs(git, q)// wait finish processing jobs
if err := q.Drain(); err != nil {
log.Printf("Error %#v\n", err)
}
}func loadJobs(q *core.Queue) {
q.Jobs <- YOUR_DATA_TYPE{}if err != nil {
q.Errors <- err
close(q.Jobs)
return
}// close the queue if your are not expecting more income data
close(q.Jobs)
}
```