generics

package
v0.0.0-...-55ea9e2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	// For simplicity here we are going to have each of these have exactly 3 values
	// and 5 slots, the 4th slot will calculate the total and the 5th slot the average.
	Data []int
}

Data will implement T in our Request[T] above

type Pipeline

type Pipeline[T any] struct {
	In  chan Request[T]
	Out chan Request[T]
	// contains filtered or unexported fields
}

Pipeline sets up a concurrent (kindof anyways) Pipeline.

func New

func New[T any](sm StateMachine[T]) *Pipeline[T]

New creates a new Pipeline that utilzes the Stage(s) in "sm".

type Request

type Request[T any] struct {
	// Ctx is the context for this request.
	Ctx context.Context
	// Err is used to store an error that occurred in the Pipeline.
	// If Err is set in any Stage, everything stops processing.
	Err error
	// Next is the next Stage to execute. If set to nil, processing stops.
	Next Stage[T]

	// Data is whatever data to use in the Pipeline.
	Data T
}

Request is a Request to execute in the Pipeline.

type Stage

type Stage[T any] func(r Request[T]) Request[T]

Stage is a stage in a statemachine.

type StateMachine

type StateMachine[T any] interface {
	Start(r Request[T]) Request[T]
}

StateMachine represents a statemachine where Start() is the entry Stage and you are directed to the next stage to run via Request[T].Next .

Jump to

Keyboard shortcuts

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