workgroup

package
v0.0.0-...-4dcfcdd Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package workgroup contains a concurrency-control utility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is a basic concurrency-control mechanism that has a variable-sized pool of worker goroutines executing callbacks from a queue. Unlike an [errgroup.Group], this types does not allow awaiting on outcomes of callbacks.

A Group is safe to call from multiple goroutines. A Group should not be copied once created.

func WithSize

func WithSize(ctx context.Context, maxWorkers int, maxQueueDepth int) *Group

WithSize returns a Group that will execute with up to the requested number of goroutines and queue up to the requested number of work elements.

func (*Group) Go

func (g *Group) Go(fn func(ctx context.Context)) error

Go executes the callback in a worker goroutine. If all workers have been created and the queue is full, an error will be returned.

func (*Group) Len

func (g *Group) Len() int

Len returns the number of queued work items.

Jump to

Keyboard shortcuts

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