Co-authored-by: Dmitry Fedotov <dmitry@uint32.ru> Co-committed-by: Dmitry Fedotov <dmitry@uint32.ru>
24 lines
532 B
Go
24 lines
532 B
Go
package script
|
|
|
|
import "context"
|
|
|
|
// Chain chains provided Processors.
|
|
// When an error is returned by a Processor in chain, processing
|
|
// stops and the error is retuned without running further stages.
|
|
func Chain(processors ...Processor) Processor {
|
|
return func(ctx context.Context, in []string) ([]string, error) {
|
|
var err error
|
|
for _, p := range processors {
|
|
// not checking ctx expiry here,
|
|
// let the processor handle it
|
|
|
|
in, err = p(ctx, in)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return in, nil
|
|
}
|
|
}
|