-- import "github.com/anikhasibul/queue"
package queue gives you a queue group accessibility. Helps you to limit goroutines, wait for the end of the all goroutines and much more...
maxRoutines := 50
q := queue.New(maxRoutines)
defer q.Close()
for i := 0; i != 1000; i++ {
q.Add()
go func(c int) {
defer q.Done()
fmt.Println(c)
}(i)
}
//wait for the end of the all jobs
q.Wait()
type Q struct {
}
Q holds a queue group and it's essentials.
func New(max int) *Q
New creates a new queue group. It takes max running jobs as a parameter.
func (q *Q) Add()
Add adds a new job to the queue.
func (q *Q) Done()
Done decrements the queue group counter.
func (q *Q) Wait()
Wait waits for the end of the all jobs.
func (q *Q) Current() int
Current returns the number of current running jobs.
func (q *Q) Close()
Close closes a queue group gracefully.