qu

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 3 Imported by: 0

README

[!CAUTION] github.com/ecnepsnai/qu is deprecated and replaced by git.ecn.io/ian/qu. All users should migrate to git.ecn.io/ian/qu for continued updates. Tag v1.0.0 is drop-in compatible copy of the last release of github.com/ecnepsnai/qu.

QU

Go Report Card Godoc Releases LICENSE

Package qu is a simple executor service. You add jobs to a queue, then run them concurrently with a configurable amount of concurrency.

Usage

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)

Documentation

Overview

Package qu is a simple executor service. You add jobs to a queue, then run them concurrently with a configurable amount of concurrency.

Deprecated: github.com/ecnepsnai/qu is deprecated and replaced by git.ecn.io/ian/qu. All users should migrate to git.ecn.io/ian/qu for continued updates. Tag v1.0.0 is drop-in compatible copy of the last release of github.com/ecnepsnai/qu.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	Done bool
	// 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 will add a new job to the queue. When the job is run it will be called with the value of payload. The job will not be invoked until queue.Run is called.

func (*Queue) Run

func (q *Queue) Run(threads int)

Run will begin to execute all of the jobs in the queue, running each job concurrently up-to the specified number of threads. Run will block until all jobs have completed. After this, the Done property on the queue will be true.

Jobs may not be executed in the same order that they were added. If any jobs panics, the panic will bubble up to here.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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