Documentation ¶
Overview ¶
Package xsync provides extra synchronization primitives to supplement the standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Select ¶
func Select(cases ...SelectCase)
Select performs a select operation on the provided cases.
Types ¶
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
A Future holds a value that might not be available yet.
func NewFuture ¶
NewFuture returns a new future and a function that completes that future with the given value. The returned complete function becomes a no-op after the first usage.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
A Queue concurrently collects values and returns them in FIFO order. A zero value Queue is ready to use.
A Queue is stopped when it is garbage collected. Therefore, a reference to the Queue must be kept alive during its use or its behavior will become undefined. Because of that, it is recommended to access the Queue's channels via the methods every time instead of storing a copy somewhere.
A Queue is initialized by calling any of its methods, so a copy of a Queue made before those methods are called is a completely independent Queue, while a copy made afterwards is the same Queue.
If a Queue's contents contain any references to the Queue itself, it can cause garbage collection to fail. For example, given a Queue[func()], if the Queue contains any closures which reference the actual instance of the Queue, the Queue's finalizer will not run until those elements have been removed from the Queue. Because of this, such a Queue will need to be manually stopped with a call to Queue.Stop.
func (*Queue[T]) Pop ¶
func (q *Queue[T]) Pop() <-chan T
Pop returns a channel that yields values from the queue when they are available. The channel will be closed when the Queue is stopped.
type SelectCase ¶
SelectCase represents either a send or receive on a channel, or a default case with no channel associated.
func Default ¶
func Default(f func()) SelectCase
Default returns a SelectCase that represents a default case. If f is not nil, it will be called if the case is selected.
func Recv ¶
func Recv[T any](c <-chan T, f func(T)) SelectCase
Recv returns a SelectCase representing single-value receive from the channel c. If f is not nil, it will be called with the result of the receive if the receive is selected.
func RecvOK ¶
func RecvOK[T any](c <-chan T, f func(T, bool)) SelectCase
RecvOK returns a SelectCase representing a two-value receive from the channel c. If f is not nil, it will be called with the result of the receive if the receive is selected.
func Send ¶
func Send[T any](c chan<- T, v T, f func()) SelectCase
Send returns a SelectCase representing a send of v to the channel c. If f is not nil, it will be called if the send is selected.
type Stopper ¶
type Stopper struct {
// contains filtered or unexported fields
}
A Stopper provides a simple way to handle a done channel for internal coordination. For coordination across API boundaries, it is generally better to use context.Context.
The zero value of a Stopper is ready to use.