Documentation ¶
Overview ¶
Copyright 2016 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Package run provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task. The package is based on golang.org/x/sync/errgroup and adds concurrency limits on top.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
A Group is a collection of goroutines working on subtasks that are part of the same overall task. The parallelization of tasks is controlled by a semaphore that is either unrestricted (allows unlimited number of concurrent tasks) or limits them to a certain amount subject to implemented strategy.
A zero Group is valid and does not cancel on error.
func WithContext ¶
WithContext returns a new group with the specified concurrency configuration.
type Option ¶
type Option func(group *Group)
Option is a configuration option for Group
func WithCPU ¶
func WithCPU() Option
WithCPU creates a new semaphore that executes as many tasks as there're CPU cores
func WithParallel ¶
WithParallel creates a new semaphore that caps the number of tasks to the specified value.
If parallel < 0, then the tasks are not capped. If parallel == 0, then the behaviour is as with parallel == 1 If parallel > 0, then the specified number of tasks is allowed to run concurrently