// WorkerId is identification of a particular runner.
// It's needed to abstract '*worker' pointer in Done channel.
-type WorkerId *worker
+type WorkerId struct {
+ *worker
+}
// WorkRunner is an interface, which every work runner should conform to.
// This is an actual implementation running Requester's Fn() function and
// completed re-inserts worker, which finished request, into proper place in the pool.
func (b *Balancer) completed(done *Done) {
fmt.Printf("completed() '%v': finished '%v'\n", done.Worker, done.Req)
- w := (*worker)(done.Worker)
+ w := done.Worker.worker
w.pending--
heap.Remove(&b.pool, w.index)
heap.Push(&b.pool, w)
pool := make(pool, n)
for i := 0; i < n; i++ {
w := worker{num: i, pending: 0, index: i}
- runners[i].InitRunner(&w)
+ runners[i].InitRunner(WorkerId{&w})
w.runner = runners[i]
pool[i] = &w
}