2020-10-03 09:57:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type worker interface {
|
|
|
|
Run(context.Context)
|
|
|
|
}
|
|
|
|
|
2020-10-21 09:26:16 +00:00
|
|
|
type workerFromFunc struct {
|
|
|
|
fn func(context.Context)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newWorkerFromFunc(fn func(ctx context.Context)) worker {
|
|
|
|
return &workerFromFunc{
|
|
|
|
fn: fn,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *workerFromFunc) Run(ctx context.Context) {
|
|
|
|
w.fn(ctx)
|
|
|
|
}
|
|
|
|
|
2020-10-03 09:57:02 +00:00
|
|
|
func startWorkers(c *cfg) {
|
|
|
|
for _, wrk := range c.workers {
|
|
|
|
c.wg.Add(1)
|
|
|
|
|
2020-10-08 13:11:34 +00:00
|
|
|
go func(w worker) {
|
|
|
|
w.Run(c.ctx)
|
2020-10-03 09:57:02 +00:00
|
|
|
c.wg.Done()
|
2020-10-08 13:11:34 +00:00
|
|
|
}(wrk)
|
2020-10-03 09:57:02 +00:00
|
|
|
}
|
|
|
|
}
|