producers

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package producers counts the goroutines that keep something alive, and decides its end under the lock that admits them.

A sync.WaitGroup cannot do that: a member must not be added from outside while Wait may be returning, and the owners of these goroutines are joined from outside by nature. A log session takes a source from an options update while its own goroutine is finishing; a session manager takes a session from a caller while it is closing. A WaitGroup in that place is a data race under -race and, in a plugin, "sync: WaitGroup is reused before previous Wait has returned": a panic that ends the process. A Group makes the end of the owner a state instead, so that a producer that races it is refused, or waited for, and never lost.

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 tracks the producers of one owner: the goroutines that go on feeding it after its own work is over. Its owner waits for them, so that it can publish its end when the last one has returned.

It does what a sync.WaitGroup does, without the one thing a WaitGroup forbids: a member cannot be added from outside while Wait may be returning, and a producer is outside by nature. Here the end of the group is a state, decided under the same lock that admits members, so a producer either joins the group or is told it is over.

A group passes through three states:

  • open: the owner's own work is still running. Start always succeeds.
  • closing: the owner has called Wait, because its own work is over, and the producers that remain are still running. Start still succeeds: a running producer keeps the owner alive (a session's watcher may add a source, and an update may restart one).
  • ended: Wait has returned, because the last producer returned. Start fails for good, and the owner's end is, or has been, published.

An owner that has to stop admitting at the moment it begins to shut down, and not when the last producer has gone, keeps its own flag under the lock that admits, and checks it before Start (a manager's Close does). The group guarantees the rest: that a producer admitted before the end is waited for, and that one that comes after it is refused.

The zero value is an open group.

func (*Group) Done

func (g *Group) Done()

Done reports that a producer registered with Start has returned. It panics when no producer is registered: a Done without a Start is a bug in the owner.

func (*Group) Freeze

func (g *Group) Freeze() (thaw func())

Freeze holds the group's lock until the returned function is called: every Start, Done and Wait blocks meanwhile. It is a seam for tests that have to hold a producer's reservation where it happens, to force an interleaving of the code that reserves it; nothing else should call it.

func (*Group) Start

func (g *Group) Start(n int) bool

Start registers n producers, each of which must call Done when it returns. It reports whether it did: it does not once the group has ended, and then registers none.

func (*Group) Wait

func (g *Group) Wait()

Wait is called by the owner when its own work is over. It returns once no producer is left, and from then on the group has ended. It may be called again, and by many goroutines.

Jump to

Keyboard shortcuts

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