Easy concurrent loops for Go.

rj 3c37c0a718 Pass lint. 2 years ago
.appveyor.yml b31bdae606 Fixed a bug in one of the tests where the loop's upper limit was not set correctly. 3 years ago
.gitlab-ci.yml 3c37c0a718 Pass lint. 2 years ago
LICENSE ef44872901 Initial commit. 3 years ago
README.md 1bf4556fc0 Added an example to the README. 3 years ago
doc.go e1a13e1d5b Added a minimum README. 3 years ago
go.mod bff930b5ef Update to use go modules. 2 years ago
pipeline.go bb2ed1f734 Created a function to create the pipeline necessary to collect mulitple errors when the loop will not terminate on the first error. 3 years ago
pipeline_test.go 8808826414 Found source of intermittent error for the test ExampleCollectErrors. 3 years ago
revive.toml 8349495781 Added a linter (revive) to the test stage. 3 years ago
runner.go 8808826414 Found source of intermittent error for the test ExampleCollectErrors. 3 years ago
runner_test.go cc7c678d58 Fixed a bug in one of the tests where the loop's upper limit was not set correctly. 3 years ago
waitgroup.go 87fcd38149 Added the type WaitGroup. This type serves the same purpose as sync.WaitGroup, but provides a simpler interface. 3 years ago
waitgroup_test.go 3c37c0a718 Pass lint. 2 years ago

README.md

parallel

Easy concurrent loops.

Package parallel provides a runner to run tasks with limited concurrency. Using this package, it should be straightforward to replace any loop with similar code that provides concurrency.

Installation

As with most projects for Go, installation is as easy as go get.

Documentation

Please refer to the documentation on godoc.org for API documentation.

An example of how the package can be used is below. The full source can be found on the Go playground.

urls := []string{
    "http://www.golang.org/",
    "http://www.google.com/",
    "http://www.somestupidname.com/",
}

// Build a runner using the default context, and which will limit
// concurrency to the number of CPUs. 
r := parallel.NewRunner(nil)
for _, url := range urls {
    url := url
    r.Go(func() {
        // Fetch the URL.
        http.Get(url)
    })
}
// Wait for all HTTP fetches to complete.
r.Wait()

Contributing

Development of this project is ongoing. If you find a bug or have any suggestions, please open an issue.

If you'd like to contribute, please fork the repository and make changes. Pull requests are welcome.

Related projects and documentation

  • golang.org/x/sync/errgroup: Package errgroup provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task.
  • github.com/juju/utils/parallel: The parallel package provides utilities for running tasks concurrently.
  • sync.WaitGroup: A WaitGroup waits for a collection of goroutines to finish.
  • Worker Pools: An example on how to implement a worker pool using goroutines and channels, provided by Go by Example.

Licensing

This project is licensed under the 3-Clause BSD License. See the LICENSE in the repository.