Repolode
sourcegraph

sourcegraph/conc

A Go library that makes structured concurrency safer and simpler, with wait groups, bounded pools, ordered streams and panic propagation.

Stars
10,435
Forks
366
Open issues
33
Last commit
2 months ago

What is it?

conc is a Go package that wraps common concurrency patterns in a scoped, easier-to-read API. Every goroutine is owned by a conc.WaitGroup, so the owner is responsible for waiting on it instead of leaving it to run unattended.

The package handles panics in spawned goroutines by catching them and re-raising them in the goroutine that calls Wait(), with the child's stack trace attached. This avoids the boilerplate of recover-and-forward code that a plain go statement requires.

On top of the wait group, conc offers bounded worker pools, pools that collect results or errors, context-cancelling pools, an ordered stream processor, and concurrent Map and ForEach helpers for slices.

Key features

  • 01WaitGroup that owns spawned goroutines and waits for them to finish.
  • 02Panics in child goroutines are re-raised on Wait() with the child's stack trace.
  • 03Bounded goroutine pools configured with WithMaxGoroutines.
  • 04Pools that collect results or errors, with optional context cancellation on first error.
  • 05Ordered stream processing with parallel tasks and serial callbacks.
  • 06Concurrent iter.Map and iter.ForEach over slices.

Use cases

  • Replacing sync.WaitGroup in services where a panic in a goroutine should not crash the process silently.
  • Running a set of tasks with a fixed upper bound on concurrent goroutines.
  • Mapping or iterating over a slice concurrently without hand-written worker loops.
  • Processing an ordered stream in parallel while preserving output order.

Quick start

  1. 1

    Add the library to your Go module

    go get github.com/sourcegraph/conc

Things to know

  • The README says the package is pre-1.0 and may have minor breaking changes before 1.0.

Topics

FAQ

What is conc?
A Go library that makes structured concurrency safer and simpler, with wait groups, bounded pools, ordered streams and panic propagation. conc is a Go package that wraps common concurrency patterns in a scoped, easier-to-read API. Every goroutine is owned by a conc.WaitGroup, so the owner is responsible for waiting on it instead of leaving it to run unattended.
Is conc free to use? What license does it have?
conc is open source under the MIT license. Check the license terms before using it in commercial products.
Is conc still maintained?
Updated within 6 months. The last commit to conc was on Sep 1, 2026.
What can I use conc for?
Replacing sync.WaitGroup in services where a panic in a goroutine should not crash the process silently. Running a set of tasks with a fixed upper bound on concurrent goroutines. Mapping or iterating over a slice concurrently without hand-written worker loops. Processing an ordered stream in parallel while preserving output order.
How do I install conc?
Add the library to your Go module: go get github.com/sourcegraph/conc
Where can I get conc?
The source code and installation instructions are on GitHub: https://github.com/sourcegraph/conc

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects