cpr

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cpr contains concurrency primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Demultiplex

func Demultiplex[T any](inChs ...<-chan T) chan T

Demultiplex demultiplexes the given channels.

func ForAll added in v0.0.16

func ForAll[T any](ts []T, f func(T)) func()

func Get

func Get[T any](ch <-chan T, errCh <-chan error) (T, bool, error)

Get gets and returns a new T from the supplied channel. It returns a T, a boolean which indicates whether the channel is still open, or an error from the supplied errCh.

func Parallel added in v0.0.16

func Parallel(fs ...func()) func()

func Pop

func Pop[T any](ctx context.Context, ch <-chan T) (T, bool, error)

Pop returns a new T from the ch. It returns a boolean which indicates whether the channel is still open. The error indicates whether the context has been canceled.

func Push

func Push[T any](ctx context.Context, ch chan<- T, ts ...T) error

Push tries to push a T to the ch. The error indicates whether the context has been canceled.

func RunTestEngine

func RunTestEngine[T any, U any](ctx context.Context, ps Processor[T, U], ts ...T) ([]U, error)

RunTestEngine runs the processor in a test engine.

Types

type Collector

type Collector[T any] struct {
	Result []T
}

Collector collects channel result into an array.

func (*Collector[T]) Sink

func (c *Collector[T]) Sink(ctx context.Context, inCh <-chan T) error

Sink implements Sink.

type Pipeline added in v0.0.16

type Pipeline interface {
	Process(context.Context) error
}

Pipeline represents a computation.

func Connect added in v0.0.16

func Connect[T any](src Source[T], snk Sink[T]) Pipeline

Connect connects a source and a sink.

type Processor

type Processor[T any, U any] interface {
	Process(context.Context, <-chan T, chan<- U) error
}

Processor processes elements.

type Producer

type Producer[T any] struct {
	Items []T
}

Producer produces values.

func (*Producer[T]) Source

func (c *Producer[T]) Source(ctx context.Context, outCh chan<- T) error

Source implements Source.

type Sink

type Sink[T any] interface {
	Sink(context.Context, <-chan T) error
}

Sink consumes elements.

type Source

type Source[T any] interface {
	Source(context.Context, chan<- T) error
}

Source generates elements.

func Compose added in v0.0.16

func Compose[T any, U any](s Source[T], p Processor[T, U]) Source[U]

Compose composes a source and a processor.

Jump to

Keyboard shortcuts

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