queue

package module
v0.0.0-...-5d242d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2019 License: MIT Imports: 0 Imported by: 1

README

queue

-- 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()

Usage

type Q
type Q struct {
}

Q holds a queue group and it's essentials.

func New
func New(max int) *Q

New creates a new queue group. It takes max running jobs as a parameter.

func (*Q) Add
func (q *Q) Add()

Add adds a new job to the queue.

func (*Q) Done
func (q *Q) Done()

Done decrements the queue group counter.

func (*Q) Wait
func (q *Q) Wait()

Wait waits for the end of the all jobs.

func (*Q) Current
func (q *Q) Current() int

Current returns the number of current running jobs.

func (*Q) Close
func (q *Q) Close()

Close closes a queue group gracefully.

Documentation

Overview

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()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Q

type Q struct {
	// contains filtered or unexported fields
}

Q holds a queue group and it's essentials.

func New

func New(max int) *Q

New creates a new queue group. It takes max running jobs as a parameter.

func (*Q) Add

func (q *Q) Add()

Add adds a new job to the queue.

func (*Q) Close

func (q *Q) Close()

Close closes a queue group gracefully.

func (*Q) Current

func (q *Q) Current() int

Current returns the number of current running jobs.

func (*Q) Done

func (q *Q) Done()

Done decrements the queue group counter.

func (*Q) Wait

func (q *Q) Wait()

Wait waits for the end of the all jobs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL