Commit 8e5ba59
authored
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.1 parent 06d3061 commit 8e5ba59
1 file changed
Lines changed: 11 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
| |||
149 | 147 | | |
150 | 148 | | |
151 | 149 | | |
152 | | - | |
| 150 | + | |
153 | 151 | | |
154 | 152 | | |
155 | 153 | | |
156 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| |||
0 commit comments