forked from TrueCloudLab/frostfs-node
40 lines
582 B
Go
40 lines
582 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type worker struct {
|
|
name string
|
|
fn func(context.Context)
|
|
}
|
|
|
|
func newWorkerFromFunc(fn func(ctx context.Context)) worker {
|
|
return worker{
|
|
fn: fn,
|
|
}
|
|
}
|
|
|
|
func startWorkers(ctx context.Context, c *cfg) {
|
|
for _, wrk := range c.workers {
|
|
startWorker(ctx, c, wrk)
|
|
}
|
|
}
|
|
|
|
func startWorker(ctx context.Context, c *cfg, wrk worker) {
|
|
c.wg.Add(1)
|
|
|
|
go func(w worker) {
|
|
w.fn(ctx)
|
|
c.wg.Done()
|
|
}(wrk)
|
|
}
|
|
|
|
func getWorker(c *cfg, name string) *worker {
|
|
for _, wrk := range c.workers {
|
|
if wrk.name == name {
|
|
return &wrk
|
|
}
|
|
}
|
|
return nil
|
|
}
|