Documentation
¶
Index ¶
- func NotifyShutdown(done chan<- struct{}, wgs ...*sync.WaitGroup)
- type Backoff
- type ContextGroup
- func (c *ContextGroup) Add(delta int)
- func (c *ContextGroup) Cancel()
- func (c *ContextGroup) Close() error
- func (c *ContextGroup) Context() context.Context
- func (c *ContextGroup) Done()
- func (c *ContextGroup) Wait()
- func (c *ContextGroup) WaitContext(ctx context.Context) error
- func (c *ContextGroup) WaitTimeout(d time.Duration) error
- type TokenBucket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NotifyShutdown ¶
Types ¶
type Backoff ¶
type Backoff struct {
// contains filtered or unexported fields
}
func NewBackoff ¶
func (*Backoff) WaitChannel ¶ added in v1.0.4
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:
- 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.
- Calling Add() after shutdown will panic.
- 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