workset

package
v0.0.0-...-e7509a3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package workset contains a synchronized work queue implementation used by inproc sweeper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item any

Item is one item that when processed may result in more items.

type WorkSet

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

WorkSet represents an unordered collection of some work items.

Each item, when processed, may produce more follow up work items.

func New

func New(work []Item, r *rand.Rand) *WorkSet

New creates a new WorkSet and seeds it with the initial set of work items.

If `r` is non-nil the workset will use it to randomize which items are picked up by Pop. Otherwise it will use the global math/rand source.

func (*WorkSet) Pop

func (ws *WorkSet) Pop(ctx context.Context) (item Item, done func([]Item))

Pop blocks until there's some work item available and then pops it.

Once it happens, it also increments "somebody is working" counter. The worker should eventually call `done(<more work items>)` or `done(nil)` to indicate that it has finished processing the item.

If there's no available work items and no one is working (and thus no new items may ever appear), returns nil. Returns nil as well if the context is canceled.

Jump to

Keyboard shortcuts

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