Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Combine ¶ added in v0.6.0
func Combine[T any, C ChannelRecv[T]](ctx context.Context, channels ...C) <-chan T
Combine returns a channel that continuously returns the result of the select until all input sources are exhauste, or the context is canceled.
func Select ¶ added in v0.6.0
A type-safe wrapper around reflect.Select. Taken from: https://stackoverflow.com/questions/19992334
Types ¶
type ChannelRecv ¶ added in v0.6.0
type ChannelRecv[T any] interface { ~chan T | ~<-chan T }
ChannelRecv is a type constraint that includes all channel types that can be recieved from.
type Error ¶
type Error string
Error defines errors that this package can produce
const (
ErrAlreadyClosed Error = "AlreadyClosed"
)
type Gate ¶
type Gate[T any] struct { // contains filtered or unexported fields }
Gate wraps a channel and allows the receiver to abruptly stop receiving messages without causing the sender to lock up.
func NewBufferedGate ¶
NewBufferedGate creates a new gate with a buffer.
func (*Gate[T]) Close ¶
Close closes the gate, drains all remaining messages, and closes the channel.
func (*Gate[T]) Receive ¶
func (this *Gate[T]) Receive() <-chan T
Receive returns a receive-only channel that can be used to receive items.
type Locker ¶ added in v0.6.0
type Locker[T any] struct { // contains filtered or unexported fields }
Locker guards access to a value. It must not be copied after first use.
func (*Locker[T]) Borrow ¶ added in v0.6.0
func (this *Locker[T]) Borrow() (T, func())
Borrow borrows the value from the locker, and returns a function that must immediately be deferred, like this:
value, done := locker.Borrow() defer done()
From the time Borrow is called to the time the done function is called, it is safe to access the locked object from within the current goroutine.
type RWLocker ¶ added in v0.7.0
type RWLocker[T any] struct { // contains filtered or unexported fields }
RWLocker guards separate read/write access to a value.
func NewRWLocker ¶ added in v0.7.0
NewRWLocker creates a new locker with the specified value. It must not be copied after first use.
func (*RWLocker[T]) Borrow ¶ added in v0.7.0
func (this *RWLocker[T]) Borrow() (T, func())
Borrow borrows the value from the locker for write access, and returns a function that must immediately be deferred, like this:
value, done := locker.Borrow() defer done()
From the time Borrow is called to the time the done function is called, it is safe to access the locked object from within the current goroutine.