Documentation ¶
Overview ¶
Package tdsync contains some useful synchronization utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SyncBackoff ¶ added in v0.30.0
func SyncBackoff(from backoff.BackOff) backoff.BackOff
SyncBackoff decorates backoff.BackOff to be thread-safe.
Types ¶
type CancellableGroup ¶
type CancellableGroup struct {
// contains filtered or unexported fields
}
CancellableGroup is simple wrapper around errgroup.Group to make group cancellation easier. Unlike WaitGroup and errgroup.Group this is not allowed to use zero value.
func NewCancellableGroup ¶
func NewCancellableGroup(parent context.Context) *CancellableGroup
NewCancellableGroup creates new CancellableGroup.
Example:
g := NewCancellableGroup(ctx) g.Go(func(ctx context.Context) error { <-ctx.Done() return ctx.Err() }) g.Cancel() g.Wait()
func (*CancellableGroup) Cancel ¶
func (g *CancellableGroup) Cancel()
Cancel cancels all goroutines in group.
Note: context cancellation error will be returned by Wait().
func (*CancellableGroup) Go ¶
func (g *CancellableGroup) Go(f func(ctx context.Context) error)
Go calls the given function in a new goroutine.
The first call to return a non-nil error cancels the group; its error will be returned by Wait.
func (*CancellableGroup) Wait ¶
func (g *CancellableGroup) Wait() error
Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.
type LogGroup ¶
type LogGroup struct {
// contains filtered or unexported fields
}
LogGroup is simple wrapper around CancellableGroup to log task state. Unlike WaitGroup and errgroup.Group this is not allowed to use zero value.
func NewLogGroup ¶
NewLogGroup creates new LogGroup.
func (*LogGroup) Cancel ¶ added in v0.21.2
func (g *LogGroup) Cancel()
Cancel cancels all goroutines in group.
Note: context cancellation error will be returned by Wait().
type Ready ¶
type Ready struct {
// contains filtered or unexported fields
}
Ready is simple signal primitive which sends signal once. This is not allowed to use zero value.
type ResetReady ¶
type ResetReady struct {
// contains filtered or unexported fields
}
ResetReady is like Ready, but can be Reset.
func (*ResetReady) Ready ¶
func (r *ResetReady) Ready() <-chan struct{}
Ready returns waiting channel.
func (*ResetReady) Signal ¶
func (r *ResetReady) Signal()
Signal sends ready signal. Can be called multiple times.
type Supervisor ¶ added in v0.22.0
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor is simple task group primitive to control multiple long-live tasks. Unlike Groups, Supervisor does not cancel when one task is failed. Unlike WaitGroup and errgroup.Group this is not allowed to use zero value.
func NewSupervisor ¶ added in v0.22.0
func NewSupervisor(parent context.Context) *Supervisor
NewSupervisor creates new Supervisor.
func (*Supervisor) Cancel ¶ added in v0.22.0
func (s *Supervisor) Cancel()
Cancel cancels all goroutines in group.
Note: context cancellation error can be returned by Wait().
func (*Supervisor) Go ¶ added in v0.22.0
func (s *Supervisor) Go(task func(ctx context.Context) error)
Go calls the given function in a new goroutine.
func (*Supervisor) Wait ¶ added in v0.22.0
func (s *Supervisor) Wait() error
Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.
func (*Supervisor) WithErrorHandler ¶ added in v0.22.0
func (s *Supervisor) WithErrorHandler(h func(err error)) *Supervisor
WithErrorHandler sets tasks error handler Must be called before any Go calls.