Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WorkerGroup ¶
type WorkerGroup struct {
// contains filtered or unexported fields
}
WorkerGroup is similar in principle to sync.WaitGroup but manages the Workers itself. This allows it to provide a few helpful features:
- Integration with the context library.
- Limit the number of concurrent Workers.
- Capture the errors returned by each Worker.
- Abort everything after a single Worker reports an error.
func NewWorkerGroup ¶
func NewWorkerGroup(ctx context.Context, workerLimit int) *WorkerGroup
NewWorkerGroup creates a new group.
func (*WorkerGroup) Start ¶
func (wg *WorkerGroup) Start(worker Worker) error
Start launches a new worker, blocking if too many workers are already running. An error indicates the group's context is closed.
func (*WorkerGroup) Wait ¶
func (wg *WorkerGroup) Wait() error
Wait blocks until all running workers have finished. An error indicates if at least one worker returned an error or was canceled.
func (*WorkerGroup) WaitError ¶
func (wg *WorkerGroup) WaitError(err error) error
Wait with a default error value that will be returned if no worker failed.
if err := wg.Start(worker); err != nil { return wg.WaitError(err) }
Click to show internal directories.
Click to hide internal directories.