pipeline

package module
v0.0.0-...-d8978e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2023 License: MIT Imports: 2 Imported by: 0

README

pipeline

A simple Go pipeline

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do[T any](ctx context.Context, source Source[T], stages ...Stage[T]) error

Do runs the pipeline specified by the source and stages. Source will produce work items and each stage will process them.

Types

type Source

type Source[T any] func(context.Context, *errgroup.Group) <-chan T

func NewSource

func NewSource[T any](sourceFn SourceFn[T]) Source[T]

NewSource creates a new source stage to procude work items. They then be processed by each stage.

type SourceFn

type SourceFn[T any] func(ctx context.Context, put func(T) error) error

SourceFn is a function to produce work items. It should call put(item) to add an item into the pipeline for processing.

type Stage

type Stage[T any] func(context.Context, *errgroup.Group, <-chan T) <-chan T

func NewStage

func NewStage[T any](fn StageFn[T]) Stage[T]

NewStage creates a new stage to process work items.

type StageFn

type StageFn[T any] func(ctx context.Context, item T) (T, error)

StageFn is a function process a work item. It takes an item as an input an return a new one after processing. The last stage is a sink stage and its output will be ignored.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL