finds.dev← search

// the find

fatih/semgroup

★ 320 · Go · BSD-3-Clause · updated Oct 2024

Like errgroup/waitgroup, but only runs a maximum of tasks at any time.

semgroup is a small Go library that runs a set of goroutines under a fixed concurrency cap, built on a weighted semaphore, and keeps every error instead of only the first one. It suits batch jobs where tasks are independent and failures should be reported per item, such as fetching or processing many records.

- The whole library is one file of wrapper code around a weighted semaphore, so you can read it in a few minutes and know exactly what happens when a task blocks on a full slot.

- Accumulating every error is the right default for independent tasks. A batch of 500 fetches reports all 37 failures in one pass instead of forcing a rerun to find the next one.

- It ships example_test.go and a GitHub Actions workflow, so the examples are compiled and run in CI rather than drifting in the README.

- The README's first example shows a fixed output order for goroutines that run concurrently. That order is not guaranteed, so anyone copying the pattern into a test gets a flaky assertion unless they sort the results first.

- As the README describes it, an error does not cancel the remaining tasks, unlike errgroup. One bad input early in a long queue still spends the whole run, and fail-fast behaviour means writing the context handling yourself.

- The last push was October 2024, and the README still uses the v := v loop-variable copy that Go 1.22 made unnecessary. Expect a low-activity maintainer, and check the module against your Go version before adopting it.

- The README shows only the printed form of the returned error. It does not say whether errors.Is and errors.As reach the individual task errors, which matters if callers need to branch on specific failures.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →