Documentation
¶
Overview ¶
Package valuewaiter provides a synchronization primitive that allows goroutines to wait for a specific value to be set.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ValueWaiter ¶
type ValueWaiter[T comparable] struct { // contains filtered or unexported fields }
ValueWaiter is a synchronization primitive that allows goroutines to wait for a specific value to be set. It is useful for cases where you want to wait for a value to change before proceeding, without busy-waiting.
func NewValueWaiter ¶
func NewValueWaiter[T comparable](initial T) *ValueWaiter[T]
NewValueWaiter creates a new ValueWaiter with an initial value.
func (*ValueWaiter[T]) GetValue ¶
func (vw *ValueWaiter[T]) GetValue() T
GetValue returns the current value of the ValueWaiter.
func (*ValueWaiter[T]) SetValue ¶
func (vw *ValueWaiter[T]) SetValue(v T)
SetValue sets the value of the ValueWaiter and unblocks all calls to WaitValue or WaitValueContext that are waiting for the specified value.
func (*ValueWaiter[T]) WaitValue ¶
func (vw *ValueWaiter[T]) WaitValue(v T)
WaitValue blocks until the ValueWaiter is set to the specified value.
func (*ValueWaiter[T]) WaitValueContext ¶
func (vw *ValueWaiter[T]) WaitValueContext(ctx context.Context, v T) error
WaitValueContext blocks until the ValueWaiter is set to the specified value or the context is cancelled. If the context is cancelled, it returns the context error, otherwise nil.