Documentation ¶
Index ¶
- Variables
- func Await[T any](ctx context.Context, ch <-chan Option[T]) (value T, err error)
- func Go[T any](ctx context.Context, f Func[T], capacity ...int) <-chan Option[T]
- func Group[T any](ctx context.Context, g func(i int) Func[T], n int, capacity ...int) <-chan Option[T]
- func TrySend[T any](ctx context.Context, ch chan<- Option[T], value T) (err error)
- func TrySendError[T any](ctx context.Context, ch chan<- Option[T], err error) (_ error)
- func With(ctx context.Context, opt ...OptFunc) (context.Context, context.CancelFunc)
- type Func
- type OptFunc
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrChannelClosed = errors.New("channel is closed")
Functions ¶
func Await ¶
Await reads channel ch and unwraps option to value and error. Can be interrupted by closed context.
func Go ¶
Go safely runs function f at a new goroutine. The ch channel will be closed automatically after f returns. If panic occurs inside of f it will be recovered and error will be written to the ch channel. If capacity is defined or greater than zero, buffered channel will be created.
func Group ¶
func Group[T any](ctx context.Context, g func(i int) Func[T], n int, capacity ...int) <-chan Option[T]
Group runs g(i) functions in parallel, their output falls into one channel. n is a count of passed functions. i is ranged from 0 to n-1.
func TrySend ¶
TrySend sends value to the ch channel, blocked until context closed or value passed to the channel.
func TrySendError ¶
TrySendError sends err to the ch channel, blocked until context closed or value passed to the channel.