channel

package
v0.0.0-...-a8c43e7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

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

Filter receives every value on ch, passes it to fn, and if fn returns true, forwards that value to the returned channel. The returned channel is closed if ctx.Done() receives or ch is closed.

func Join2

func Join2[T, U any](ctx context.Context, ch1 <-chan T, ch2 <-chan U) <-chan values.Result[values.Tuple[T, U]]

Join2 takes two channels and returns one that will either receive the values of the two, or receive a values.Error if one of the following happens:

1. ctx.Done() receives before both channels receive 2. Either channel is closed at any time

THIS FUNCTION IS NOT YET IMPLEMENTED

func Map

func Map[T, U any](
	ctx context.Context,
	ch <-chan T,
	fn func(T) U,
) <-chan U

Map starts listens on ch in a background goroutine. Upon receiving a value, it calls fn(receivedValue) and sends the result to the channel this function returns.

If ch is closed or ctx.Done() receives, this function stops receiving on ch and closes the returned channel.

func ReceiveChanWithContext

func ReceiveChanWithContext[T any](ctx context.Context, ch <-chan T) <-chan values.Result[T]

ReceiveChanWithContext listens on ch in the background and returns a channel that follows the following rules:

1. If ctx.Done() receives before ch does, the returned channel will receive a values.Error and then be closed 2. If ch is closed before anything else, the returned channel will receive a values.Error and then be closed 3. If ch receives a value, the returned channel will receive that value and then be closed

func RecieveWithContext

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

ReceiveWithContext blocks until ch receives a value, is closed, or ctx.Done() receives. In the first case, this function returns the value received and a nil error. In the latter two cases, it returns the zero value of T and a descriptive, non-nil error

func SendWithContext

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

SendWithContext either sends val to ch and returns nil or, if ctx.Done() receives, returns ctx.Err()

Types

This section is empty.

Jump to

Keyboard shortcuts

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