feat: revise API, add README.md, LICENSE (#2)

Co-authored-by: Dmitry Fedotov <dmitry@uint32.ru>
Co-committed-by: Dmitry Fedotov <dmitry@uint32.ru>
This commit is contained in:
2025-08-31 13:38:54 +03:00
committed by Dmitry
parent 858cae9547
commit 454c632462
12 changed files with 175 additions and 22 deletions

View File

@@ -28,13 +28,13 @@ type Reader interface {
// Read is called by Processor to obtain input
// for processing. Read must return EOF/io.EOF to indicate
// that there is no more input.
Read(context.Context) ([]string, error)
Read() ([]string, error)
}
type Writer interface {
// Write is called by Processor to record
// output.
Write(context.Context, []string) error
Write([]string) error
}
// Processor accepts string slice, does what it should
@@ -76,7 +76,7 @@ func Run(ctx context.Context, r RunConfig) error {
defer close(rdch)
for range r.Offset {
_, err := r.Input.Read(ctx)
_, err := r.Input.Read()
if err != nil {
return fmt.Errorf("could not advance to required offset: %w", err)
}
@@ -84,7 +84,7 @@ func Run(ctx context.Context, r RunConfig) error {
count := 0
for {
inp, err := r.Input.Read(ctx)
inp, err := r.Input.Read()
if err != nil && errors.Is(err, EOF) {
return nil
} else if err != nil {
@@ -111,8 +111,10 @@ func Run(ctx context.Context, r RunConfig) error {
grp.Go(func() error {
// not paying attention to context here
// because we must complete writes
// this is run within group so that write
// error would cancel group context
for outp := range wrch {
if err := r.Output.Write(ctx, outp); err != nil {
if err := r.Output.Write(outp); err != nil {
return err
}
}