Documentation
¶
Overview ¶
Package xsync provides synchronization utilities. It is an extension to the standard sync package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeObservable ¶ added in v0.28.0
func ChangeObservable[T comparable](o *Observable[T], v T) bool
ChangeObservable changes the value of o to v, unless v is already its current value.
It returns true if the value was changed, in which case the channel returned by any prior call to Observable.Load is closed.
Types ¶
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
Future is a container for a value that may not yet be available.
func (*Future[T]) Chan ¶ added in v0.30.0
func (a *Future[T]) Chan() <-chan struct{}
Chan returns a channel that is closed when the value becomes available.
func (*Future[T]) Store ¶
Store sets the value of the Future.
It returns false if the value was already set.
type FutureR ¶ added in v0.30.0
type FutureR[T any] interface { Load() (T, bool) Wait() T WaitContext(ctx context.Context) (T, error) Chan() <-chan struct{} }
FutureR is the receive-only view of a Future, analogous to a receive-only channel (<-chan) for a bidirectional channel.
It exposes the methods that read or wait for the value, but not Future.Store. A *Future satisfies FutureR without conversion.
type Latch ¶ added in v0.20.1
type Latch struct {
// contains filtered or unexported fields
}
Latch is a synchronization primitive that allows multiple goroutines to wait until the latch is set. Latches cannot be reset.
func (*Latch) Chan ¶ added in v0.20.1
func (l *Latch) Chan() <-chan struct{}
Chan returns a channel that is closed when the latch is set.
type LatchR ¶ added in v0.30.0
type LatchR interface {
IsSet() bool
Wait()
WaitContext(ctx context.Context) error
Chan() <-chan struct{}
}
LatchR is the receive-only view of a Latch, analogous to a receive-only channel (<-chan) for a bidirectional channel.
It exposes the methods that observe or wait on the latch, but not Latch.Set. A *Latch satisfies LatchR without conversion.
type Observable ¶ added in v0.20.1
type Observable[T any] struct { // contains filtered or unexported fields }
Observable is an atomic value that can be observed for changes.
func (*Observable[T]) Load ¶ added in v0.20.1
func (o *Observable[T]) Load() (T, <-chan struct{})
Load returns the current value and a channel that is closed when that is replaced by a subsequent call to Store.
func (*Observable[T]) Store ¶ added in v0.20.1
func (o *Observable[T]) Store(v T)
Store updates the value.
type ObservableR ¶ added in v0.30.0
type ObservableR[T any] interface { Load() (T, <-chan struct{}) }
ObservableR is the receive-only view of an Observable, analogous to a receive-only channel (<-chan) for a bidirectional channel.
It exposes Observable.Load, but not Observable.Store. An *Observable satisfies ObservableR without conversion.
type Signal ¶ added in v0.27.6
type Signal struct {
// contains filtered or unexported fields
}
Signal is a synchronization primitive that allows one goroutine to notify another that some event has occurred.
A signal can be notified repeatedly. Each notification unblocks at most one waiting goroutine and is consumed by it. Notifications that occur while another is already pending are coalesced into one.
func (*Signal) Chan ¶ added in v0.27.6
func (s *Signal) Chan() <-chan struct{}
Chan returns a channel that unblocks when the signal is notified.
Receiving from the channel consumes the pending notification, exactly as Signal.Wait does.
func (*Signal) Notify ¶ added in v0.27.6
Notify unblocks one waiting goroutine.
If there are no waiting goroutines, the notification remains pending and a future waiting goroutine will unblock immediately.
It returns true if the notification was recorded, or false if one was already pending.
type SignalR ¶ added in v0.30.0
SignalR is the receive-only view of a Signal, analogous to a receive-only channel (<-chan) for a bidirectional channel.
It exposes the methods that wait on the signal, but not Signal.Notify. A *Signal satisfies SignalR without conversion.
As with a channel, receiving consumes the notification. If several goroutines wait on the same SignalR, each notification unblocks only one of them.
type SucceedOnce ¶
type SucceedOnce struct {
// contains filtered or unexported fields
}
SucceedOnce is a sync.Once variant that allows for the operation to fail.