fix: obey main context
This commit is contained in:
13
runner.go
13
runner.go
@@ -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 {
|
||||
|
Reference in New Issue
Block a user