SIGN IN SIGN UP
sourcegraph / conc UNCLAIMED

Better structured concurrency for go

0 0 1 Go

always spawn a worker with the task it was supposed to complete (#112)

For "unlimited" pools, in the original code:

```go
p.handle.Go(p.worker)
p.tasks <- f
```

If in between the call to `handle.Go` and sending the task to the
worker, another goroutine would call `pool.Go`, that task would "hijack"
the newly created worker, causing the original send to block. This is
undesirable behavior if the pool is unlimited.

The solution was to add an `initialFunc` to the worker, which will be
executed before the worker starts waiting for new tasks. This ensures
that a worker will first complete the task it was supposed to, then
complete others.
L
Link512 committed
8e5ba59e78214e2d8d3ea2c78ef6cf2693bedaa8
Parent: 06d3061
Committed by GitHub <noreply@github.com> on 5/3/2023, 4:23:57 AM