frostfs-node/cmd/frostfs-node/worker.go
Dmitrii Stepanov a7c79c773a [#168] node: Refactor node config
Resolve containedctx linter for cfg

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-03-31 09:32:59 +03:00

49 lines
760 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 delWorker(c *cfg, name string) {
for i, worker := range c.workers {
if worker.name == name {
c.workers = append(c.workers[:i], c.workers[i+1:]...)
return
}
}
}
func getWorker(c *cfg, name string) *worker {
for _, wrk := range c.workers {
if wrk.name == name {
return &wrk
}
}
return nil
}