channels

package module
v0.0.0-...-712f4cf Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 4 Imported by: 0

README

package channels

package channels provides some helper functions for working with channels, including ways to convert them into slices. none of the functions are blocking - if a context is not provided, context.Background() is used.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChannelClosed = errors.New("channel is closed (returned !ok)")
)

Functions

func ChannelToSlice

func ChannelToSlice[T any](c <-chan T) []T

func ChannelToSliceWithContext

func ChannelToSliceWithContext[T any](ctx context.Context, c <-chan T) []T

func CopyChannelWithContext

func CopyChannelWithContext[T any](ctx context.Context, c <-chan T) (a, b <-chan T)

func MergeChannels

func MergeChannels[T any](bufferSize int, channels ...<-chan T) <-chan T

func MergeChannelsWithContext

func MergeChannelsWithContext[T any](ctx context.Context, bufferSize int, channels ...<-chan T) <-chan T

could be problematic in certain situations because it launches one goroutine per incoming channel. this shouldn't typically be a problem with a small number of channels, or when the channels producers aren't very busy, but it's worth noting.

func ProcessChannelThroughFunction

func ProcessChannelThroughFunction[T any](ctx context.Context, c <-chan T, workCallback ChannelPipelineWorkFunction[T]) <-chan T

func SliceToChannel

func SliceToChannel[T any](s []T, bufferSize int) <-chan T

func SliceToChannelWithContext

func SliceToChannelWithContext[T any](ctx context.Context, s []T, bufferSize int) <-chan T

func TryAddToChannel

func TryAddToChannel[T any](ctx context.Context, c chan<- T, t T) error

func TrySelectFromChannel

func TrySelectFromChannel[T any](ctx context.Context, c <-chan T) (T, error)

Types

type ChannelPipelineWorkFunction

type ChannelPipelineWorkFunction[T any] func(T) T

Jump to

Keyboard shortcuts

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