Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What comes handy is this [1] link, but I will update if I get any better links or others might chime in.

[1] https://blog.golang.org/pipelines

It is a very long doc, but that also shows that concurrency has so many patterns one might like.

My own pattern is typically

1. Decide level of parallelism ahead of time and start workers (that many `go X()` invocations 2. Setup sync.Waitgroup for the same count 3. Create two channels, one for each direction. 4. Job itself needs some sort of struct to hold details

Most of my jobs don't support mid-work cancelation, so I don't bother with anything else.



Your 1. and 2. are merged in the almost-stdlib package errgroup: https://pkg.go.dev/golang.org/x/sync/errgroup.

It also uses context (useful for long running, concurrent jobs) and handles mid-work cancellation




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: