anychan

package module
v0.0.0-...-dea990b Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 1 Imported by: 0

README

Truly generic Go channels

Send anything on that channel! Without blocking indefinitely!

foos := anychan.NewChannel[foo]()

go func() {
    err := foos.Send(ctx, foo("bar"))
    must.Nil(err)
    foos.Close()
}()

something, more, err := foos.Receive(ctx)

The channel cannot be used in a select branch currently. That may be added if the need arises.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel[T any] struct {
	// contains filtered or unexported fields
}

Channel wraps a channel of generic type T.

func NewChannel

func NewChannel[T any]() *Channel[T]

NewChannel creates a new channel of generic type T.

func (*Channel[T]) Close

func (c *Channel[T]) Close()

Close calls close on the channel.

func (*Channel[T]) Receive

func (c *Channel[T]) Receive(ctx context.Context) (result T, more bool, err error)

Receive reads something of generic type T from the channel.

Include timeout/deadline in the context for the operation to not block indefinitely.

func (*Channel[T]) Send

func (c *Channel[T]) Send(ctx context.Context, something T) error

Send sends something of generic type T on the channel.

Include timeout/deadline in the context for the operation to not block indefinitely.

Jump to

Keyboard shortcuts

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