chanutil

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 1 Imported by: 2

README

chanutil

Go Reference

Some utilities for interacting with channels that I use in my code.

  • Get - receive from a channel in a blocking manner, but return if a context expires.
  • Put - the same, for sending to a channel.

Currently, it's so small, that it probably makes no sense to use it. Feel free to just steal the code you want, no need to introduce unnecessary dependency on this lib. It's MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

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

Get tries to read a message from a channel, blocking until it succeeds or the context gets cancelled or expires.

Returns a pointer to the message if it was received successfuly (nil otherwise), a bool equal to true if the channel isn't closed, and ctx.Err() if the context expired/got cancelled.

func Put

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

Put tries to put a message in a channel, blocking until it succeeds or the context gets cancelled or expires. Returns ctx.Err() if the message was not sent successfuly.

Types

This section is empty.

Jump to

Keyboard shortcuts

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