qu

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: MIT Imports: 3 Imported by: 0

README

DS

Go Report Card Godoc Releases LICENSE

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.

Usage

queue := &qu.Queue{}

job := func(payload interface{}) {
    // do something with your payload
}

// Add a job to the queue
queue.Add(job, "your payload")

// Run through the queue with 2 threads
queue.Run(2)

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

func (q *Queue) Run(threads int)

Run execute all jobs in the queue with the specified number of threads. Will block until all jobs have completed.

Example
package main

import (
	"time"

	"github.com/ecnepsnai/qu"
)

func main() {
	queue := &qu.Queue{}

	job := func(payload interface{}) {
		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)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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