sync

package module
v0.0.0-...-05eb9c8 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedWaitGroup

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

BoundedWaitGroup is a wait group which has a limit boundary meaning it will wait for Done() to be called before releasing Add(n) if the limit has been reached.

func NewBoundedWaitGroup

func NewBoundedWaitGroup(cap int) BoundedWaitGroup

NewBoundedWaitGroup returns a new BoundedWaitGroup

func (*BoundedWaitGroup) Add

func (bwg *BoundedWaitGroup) Add(delta int)

Add adds delta, which may be negative, to the BoundedWaitGroup counter. If counter + delta is greater that the cap of the BoundedWaitGroup then Add would block until there is enough slots made available in the the WaitGroup.

func (*BoundedWaitGroup) Done

func (bwg *BoundedWaitGroup) Done()

Done decrements the WaitGroup counter by one.

func (*BoundedWaitGroup) Wait

func (bwg *BoundedWaitGroup) Wait()

Wait blocks until the WaitGroup counter is zero.

type CancelableWaitGroup

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

CancelableWaitGroup is a Waiter that can be canceled via a context. If the context is canceled then Waiter.Wait() will return even if Waiter.Done() has not been called as much as Waiter.Add(). Note that this waiter can only be used once. If Add() is used after the context has been canceled or after Done() has been called as much as Add() then it will panic.

func NewCancelableWaitGroup

func NewCancelableWaitGroup(context context.Context, cap int) *CancelableWaitGroup

NewCancelableWaitGroup returns a CancelableWaitGroup which has been initialized.

func (*CancelableWaitGroup) Add

func (wg *CancelableWaitGroup) Add(n int)

Add adds n tasks and does not return until wg.cur + n <= wg.cap. However, it does return if the context is canceled.

func (*CancelableWaitGroup) Done

func (wg *CancelableWaitGroup) Done()

Done decreases the number of running tasks.

func (*CancelableWaitGroup) Wait

func (wg *CancelableWaitGroup) Wait()

Wait waits until the number of tasks is 0 or until the context is canceled.

type Waiter

type Waiter interface {
	Add(int)
	Done()
	Wait()
}

Waiter interface

func NewWaiter

func NewWaiter(cap int) Waiter

NewWaiter returns a Waiter, a sync.WaitGroup if cap i <= 0, a BoundedWaitGroup otherwise.

Jump to

Keyboard shortcuts

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