channels

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package channels contains various generic helpers for working with channels

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast[T any](input <-chan T, outputs ...chan<- T)

Broadcast relays all the messages received on input to outputs. It stops when input is closed, and closes outputs at that point. For efficient functionality, the outputs should be buffered.

func Broadcaster

func Broadcaster[T any](input <-chan T, outputs ...chan<- T) errGroupFunc

Broadcaster wraps Broadcast to simplify errgroup setup

func Filter

func Filter[T, U any](
	input <-chan T,
	filter func(T) (U, error),
	output chan<- U,
) error

Filter reads each item from input and passes it to filter. If filter returns an error, it stops and returns that, otherwise it forwards filter's result to output. When input ends, output is closed and Filter returns nil.

func FilterMany

func FilterMany[T, U any](
	input <-chan T,
	filter func(T) ([]U, error),
	output chan<- U,
) error

FilterMany is like Filter, but allows the filter to return many output items for each input item.

func Filterer

func Filterer[T, U any](
	input <-chan T,
	filter func(T) (U, error),
	output chan<- U,
) errGroupFunc

Filterer wraps Filter for easy errgroup setup

func FiltererMany

func FiltererMany[T, U any](
	input <-chan T,
	filter func(T) ([]U, error),
	output chan<- U,
) errGroupFunc

FiltererMany wraps FilterMany for easy errgroup setup

func Process

func Process[T any](input <-chan T, action func(T) error) error

Process reads each item from input and passes it to action. If filter returns an error, it stops and returns that, otherwise it returns nil when input is closed.

func Processor

func Processor[T any](input <-chan T, action func(T) error) errGroupFunc

Processor wraps Process to simplify errgroup setup

Types

This section is empty.

Jump to

Keyboard shortcuts

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