Documentation
¶
Overview ¶
Package usync extends sync.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Combine ¶
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 ¶
A type-safe wrapper around reflect.Select. Taken from: https://stackoverflow.com/questions/19992334
Types ¶
type ChannelRecv ¶
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]) Receive ¶
func (this *Gate[T]) Receive() <-chan T
Receive returns a receive-only channel that can be used to receive items.
type Monitor ¶ added in v0.9.0
type Monitor[T any] struct { // contains filtered or unexported fields }
Monitor guards access to a value. It must not be copied after first use.
func NewMonitor ¶ added in v0.9.0
NewMonitor creates a new Monitor with the specified value.
func (*Monitor[T]) Borrow ¶ added in v0.9.0
func (this *Monitor[T]) Borrow() (T, func())
Borrow borrows the value from the Monitor, and returns a function that must immediately be deferred, like this:
value, done := monitor.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.
func (*Monitor[T]) BorrowReturn ¶ added in v0.9.0
func (this *Monitor[T]) BorrowReturn() (T, func(T))
BorrowReturn is like borrow, but returns a "done" function that takes in an updated value. The intended use of this function is like this:
value, done := monitor.BorrowReturn() defer done(value)
type RWMonitor ¶ added in v0.9.0
type RWMonitor[T any] struct { // contains filtered or unexported fields }
RWMonitor guards separate read/write access to a value.
func NewRWMonitor ¶ added in v0.9.0
NewRWMonitor creates a new Monitor with the specified value. It must not be copied after first use.
func (*RWMonitor[T]) Borrow ¶ added in v0.9.0
func (this *RWMonitor[T]) Borrow() (T, func())
Borrow borrows the value from the Monitor for write access, and returns a function that must immediately be deferred, like this:
value, done := monitor.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.
func (*RWMonitor[T]) BorrowReturn ¶ added in v0.9.0
func (this *RWMonitor[T]) BorrowReturn() (T, func(T))
BorrowReturn is like borrow, but returns a "done" function that takes in an updated value. The intended use of this function is like this:
value, done := monitor.BorrowReturn() defer done(value)