wqueue

package
v0.0.0-...-fb49ba0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package wqueue implements a work queue, with independent internal subqueues.

Inspired by Brian C. Mills' "Rethinking Classical Concurrency Patterns" talk, specifically the queue that passes data between putters and workers to coordinate state changes between channels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attacher

type Attacher func(ctx context.Context) (context.Context, context.CancelFunc)

An Attacher attaches an extra cancelletion to the provided context.

type Queue

type Queue[K comparable] struct {
	// contains filtered or unexported fields
}

Queue is a work queue, consisting of multiple subqueues which can operate independently while sharing the same workers.

func NewQueue

func NewQueue[K comparable](limit int) *Queue[K]

NewQueue creates a new Queue which can grow to a maximum size of limit.

func (*Queue[K]) Put

func (q *Queue[K]) Put(ctx context.Context, key K, fn WorkFunc) error

Put puts the worker function into the keyed subqueue. This function will be called at some point in the future by a worker, but never concurrently with other items in the keyed subqueue.

func (*Queue[K]) Worker

func (q *Queue[K]) Worker(ctx context.Context) error

Worker runs items from the queues, exiting when the context has been canceled.

type WorkFunc

type WorkFunc func(attach Attacher)

WorkFunc is a function called by a worker. The attach function can be used to attach the canceleation of the worker to another context.

Jump to

Keyboard shortcuts

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