waitgroup

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generation added in v1.7.4

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

Generation is one immutable leadership generation for a key. Followers keep this token after it completes so Regroup can link every member of that cohort to the same next generation, even when the next leader finishes before a late follower wakes.

func (*Generation) Done added in v1.7.4

func (g *Generation) Done() <-chan struct{}

Done returns a channel closed when this generation's leader finishes or its bounded wait expires.

func (*Generation) Err added in v1.7.4

func (g *Generation) Err() error

Err reports why the generation ended. DeadlineExceeded distinguishes an abandoned/timed-out leader from a normal Done cancellation.

type WaitGroup

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

WaitGroup waits for other same processes based key with timeout.

func New

func New(timeout time.Duration) *WaitGroup

New return a new WaitGroup with timeout.

func (*WaitGroup) Add

func (wg *WaitGroup) Add(key uint64)

(*WaitGroup).Add add adds a new caller or if the caller exists increment dups with key.

func (*WaitGroup) Done

func (wg *WaitGroup) Done(key uint64)

(*WaitGroup).Done done cancels the group context or if the caller dups more then zero, decrements the dups with key.

func (*WaitGroup) DoneGeneration added in v1.7.4

func (wg *WaitGroup) DoneGeneration(key uint64, generation *Generation)

DoneGeneration completes generation and removes it only if it is still the current value for key. The identity check prevents an old, timed-out leader from deleting a newer regroup generation.

func (*WaitGroup) Get

func (wg *WaitGroup) Get(key uint64) int

(*WaitGroup).Get get return count of dups with key.

func (*WaitGroup) Join

func (wg *WaitGroup) Join(key uint64) <-chan struct{}

Join atomically decides leadership for key. It is the legacy key-only API; callers must not mix Join/Done with JoinGeneration/DoneGeneration for the same key. It returns nil and registers the caller as the leader (caller must call Done when finished). If a leader already exists, Join returns a channel that closes when the leader finishes; followers must NOT call Done — they never registered as a participant, so calling Done would either over-decrement the dup counter or cancel the leader's context out from under it.

This API closes the Wait-then-Add race in the older Wait/Add sequence: two simultaneous first callers both saw "no leader" and both became leaders, so the dedup didn't actually dedup.

func (*WaitGroup) JoinGeneration added in v1.7.4

func (wg *WaitGroup) JoinGeneration(key uint64) (*Generation, bool)

JoinGeneration atomically decides leadership for key and returns the exact generation token. The leader must call DoneGeneration with that same token; followers wait on Generation.Done and must not call DoneGeneration.

func (*WaitGroup) Regroup added in v1.7.4

func (wg *WaitGroup) Regroup(key uint64, previous *Generation) (*Generation, bool)

Regroup links every follower of previous to one common next generation for key. Callers must wait for previous.Done and must handle a timed-out generation without regrouping. The link is retained on previous, so a late follower cannot create a third generation merely because the shared next leader already completed.

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait(key uint64)

(*WaitGroup).Wait wait blocks until WaitGroup context cancelled or timedout with key.

Jump to

Keyboard shortcuts

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