fix: obey main context

This commit is contained in:
2025-08-30 23:26:56 +03:00
parent ec5db88f97
commit 82a90e8107

View File

@@ -37,9 +37,9 @@ type Writer interface {
Write(context.Context, []string) error
}
// Process accepts string slice, does what it should
// Processor accepts string slice, does what it should
// and returns output. Non-nil error returned
// by Processor terminates stops further processing.
// by Processor stops further processing.
type Processor func(context.Context, []string) ([]string, error)
type RunConfig struct {
@@ -118,6 +118,7 @@ func Run(ctx context.Context, r RunConfig) error {
return nil
})
// run processing routines
grp.Go(func() error {
// will close write chan once
// all workers are done
@@ -136,12 +137,16 @@ func Run(ctx context.Context, r RunConfig) error {
}
wrch <- result
// if one of workers died or parent context expired
// we should die too
if err := innrctx.Err(); err != nil {
return nil
}
}
return nil
})
}
if err := workergrp.Wait(); err != nil {