frostfs-node/cmd/frostfs-node/worker.go
Dmitrii Stepanov 825f65f79e [#873] node: Start metrics and pprof as soon as possible
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-12-21 15:09:51 +00:00

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
}