Documentation
¶
Overview ¶
Package qu is a executor service in golang.
You add your jobs to a list, then run them in parallel with a configurable amount of concurrency.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue describes a queue of jobs
func (*Queue) Add ¶
func (q *Queue) Add(job func(payload interface{}), payload interface{})
Add add a new job to the queue. Will be called with the given payload.
func (*Queue) Run ¶
Run execute all jobs in the queue with the specified number of threads. Will block until all jobs have completed.
Example ¶
package main
import (
"fmt"
"time"
"github.com/ecnepsnai/qu"
)
func main() {
queue := &qu.Queue{}
job := func(payload interface{}) {
i := payload.(int)
fmt.Printf("Job %d\n", i)
time.Sleep(1 * time.Millisecond)
}
// Add 50 jobs to the queue
i := 0
for i < 50 {
queue.Add(job, i)
i++
}
// Go through those 50 jobs across 2 threads
queue.Run(2)
}
Output:
Click to show internal directories.
Click to hide internal directories.