concurrency

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: BSD-2-Clause Imports: 4 Imported by: 0

README

concurrency

A golang library that contains concurrency utils.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotifyShutdown

func NotifyShutdown(done chan<- struct{}, wgs ...*sync.WaitGroup)

Types

type Backoff

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

func NewBackoff

func NewBackoff(minBackoff, maxBackoff time.Duration) *Backoff

func (*Backoff) Backoff

func (b *Backoff) Backoff()

func (*Backoff) Recover

func (b *Backoff) Recover()

func (*Backoff) StopTimer added in v1.0.4

func (b *Backoff) StopTimer()

func (*Backoff) Wait

func (b *Backoff) Wait() error

func (*Backoff) WaitChannel added in v1.0.4

func (b *Backoff) WaitChannel() <-chan time.Time

func (*Backoff) WaitContext

func (b *Backoff) WaitContext(ctx context.Context) error

type ContextGroup

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

ContextGroup is similar to a sync.WaitGroup, except that it supports cancellation via a shared context. It is useful for implementing components that support both Graceful shutdown (with timeouts) and forced cancellation. Its use is subject to the following constraints:

  1. After Wait(), WaitTimeout() or Close() is called, shutdown will be triggered when the counter reaches zero, and all goroutines blocked on Wait will be released.
  2. Calling Add() after shutdown will panic.
  3. To avoid a resource leak, you must arrange to call Cancel() (directly, or via Close()).

func NewContextGroup

func NewContextGroup() *ContextGroup

func (*ContextGroup) Add

func (c *ContextGroup) Add(delta int)

Add adds delta, which may be negative, to the ContextGroup counter. If the counter becomes zero, all goroutines blocked on Wait are released. If the counter goes negative, Add panics. Similar, calling Add once shutdown is complete will also panic.

func (*ContextGroup) Cancel

func (c *ContextGroup) Cancel()

Cancel cancels the ContextGroup context.

func (*ContextGroup) Close

func (c *ContextGroup) Close() error

Close is equivalent to running Cancel() followed by Wait().

func (*ContextGroup) Context

func (c *ContextGroup) Context() context.Context

Context returns the shared context of the ContextGroup.

func (*ContextGroup) Done

func (c *ContextGroup) Done()

Done decrements the ContextGroup counter by one.

func (*ContextGroup) Wait

func (c *ContextGroup) Wait()

Wait blocks until the ContextGroup counter is zero.

func (*ContextGroup) WaitContext

func (c *ContextGroup) WaitContext(ctx context.Context) error

WaitContext blocks until the ContextGroup counter is zero or the provided context is completed. If the context is completed before the counter reaches zero, it returns the context's error.

func (*ContextGroup) WaitTimeout

func (c *ContextGroup) WaitTimeout(d time.Duration) error

WaitTimeout blocks until the ContextGroup counter is zero or the provided duration has elapsed. If the duration elapses before the counter reaches zero, it returns a context deadline exceeded error.

type TokenBucket

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

func NewTokenBucket

func NewTokenBucket(maxTokens float64, refillRate float64, refillDuration time.Duration) *TokenBucket

func (*TokenBucket) Take

func (tb *TokenBucket) Take(amount float64) bool

Jump to

Keyboard shortcuts

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