package tdsync
Import Path
github.com/gotd/td/internal/tdsync (on go.dev)
Dependency Relation
imports 9 packages, and imported by 5 packages
Involved Source Files
backoff.go
Package tdsync contains some useful synchronization utilities.
log_group.go
ready.go
reset_ready.go
supervisor.go
Package-Level Type Names (total 6, in which 5 are exported)
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.
cancel context.CancelFunc
ctx context.Context
group *errgroup.Group
Cancel cancels all goroutines in group.
Note: context cancellation error will be returned by Wait().
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.
Wait blocks until all function calls from the Go method have returned, then
returns the first non-nil error (if any) from them.
func NewCancellableGroup(parent context.Context) *CancellableGroup
LogGroup is simple wrapper around CancellableGroup to log task state.
Unlike WaitGroup and errgroup.Group this is not allowed to use zero value.
clock clock.Clock
group CancellableGroup
log *zap.Logger
Cancel cancels all goroutines in group.
Note: context cancellation error will be returned by Wait().
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.
SetClock sets Clock to use.
Wait blocks until all function calls from the Go method have returned, then
returns the first non-nil error (if any) from them.
func NewLogGroup(parent context.Context, log *zap.Logger) *LogGroup
Ready is simple signal primitive which sends signal once.
This is not allowed to use zero value.
done int32
wait chan struct{}
Ready returns waiting channel.
Signal sends ready signal.
Can be called multiple times.
(*Ready) reset()
func NewReady() *Ready
ResetReady is like Ready, but can be Reset.
lock sync.Mutex
ready Ready
Ready returns waiting channel.
Reset resets underlying Ready.
Signal sends ready signal.
Can be called multiple times.
func NewResetReady() *ResetReady
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.
cancel context.CancelFunc
ctx context.Context
onError func(err error)
wg sync.WaitGroup
Cancel cancels all goroutines in group.
Note: context cancellation error can be returned by Wait().
Go calls the given function in a new goroutine.
Wait blocks until all function calls from the Go method have returned, then
returns the first non-nil error (if any) from them.
WithErrorHandler sets tasks error handler
Must be called before any Go calls.
func NewSupervisor(parent context.Context) *Supervisor
func (*Supervisor).WithErrorHandler(h func(err error)) *Supervisor
Package-Level Functions (total 6, all are exported)
NewCancellableGroup creates new CancellableGroup.
Example:
g := NewCancellableGroup(ctx)
g.Go(func(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
})
g.Cancel()
g.Wait()
NewLogGroup creates new LogGroup.
NewReady creates new Ready.
NewResetReady creates new ResetReady.
NewSupervisor creates new Supervisor.
SyncBackoff decorates backoff.BackOff to be thread-safe.
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |