|
|
|
|
|
by diegoholiveira
15 days ago
|
|
The post advocates for structured concurrency, but it compares a language primitive with a library abstraction. In Go, implementing the same basic nursery concept is straightforward with `golang.org/x/sync/errgroup`: g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
return task1(ctx)
})
g.Go(func() error {
return task2(ctx)
})
return g.Wait()
If you don't care about error propagation or cancellation at all, the standard library also provides `sync.WaitGroup`.The author also seems to argue that structured concurrency is always preferable, but I do not think that is true. There are valid use cases for unstructured concurrency, particularly for long-lived or independently managed tasks. |
|