Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ValueWatcher ¶
type ValueWatcher[T any] struct { // contains filtered or unexported fields }
ValueWatcher holds a reference to a value. Multiple goroutines are able to put or retrieve the value into/from the ValueWatcher, as well as wait for a certain value to be put into the ValueWatcher. It is similar to atomic.Value except the caller can call Watch to be notified each time the value in ValueWatcher changes.
func (*ValueWatcher[T]) Get ¶
func (vw *ValueWatcher[T]) Get() T
Get returns the current value stored in ValueWatcher.
func (*ValueWatcher[T]) Set ¶
func (vw *ValueWatcher[T]) Set(val T)
Set stores val in ValueWatcher and notifies all goroutines that called Watch about the new value, if such goroutines exists.
func (*ValueWatcher[T]) Watch ¶
func (vw *ValueWatcher[T]) Watch(ctx context.Context, f ValueWatcherFunc[T]) (T, error)
Watch blocks and calls f for every value that is put into the ValueWatcher. Once f returns true it stops blocking and returns nil. First call to f will be with the current value stored in ValueWatcher. Note that if no value was stored in ValueWatcher yet, the zero value of type T will be passed to f.
Watch can be safely called by multiple goroutines. If the context gets cancelled before f returns true, the function will return the context error.
type ValueWatcherFunc ¶
func WatchValues ¶
func WatchValues[T comparable](want ...T) ValueWatcherFunc[T]
WatchValues is a utility function for creating a simple ValueWatcherFunc that waits for one of the supplied values.
type WaitGroup ¶
WaitGroup is a sync.WaitGroup with utility methods.
func (*WaitGroup) Add ¶
Add adds delta, which may be negative, to the WaitGroup counter. If the counter becomes zero, all goroutines blocked on Wait are released. If the counter goes negative, Add panics.
Note that calls with a positive delta that occur when the counter is zero must happen before a Wait. Calls with a negative delta, or calls with a positive delta that start when the counter is greater than zero, may happen at any time. Typically this means the calls to Add should execute before the statement creating the goroutine or other event to be waited for. If a WaitGroup is reused to wait for several independent sets of events, new Add calls must happen after all previous Wait calls have returned. See the WaitGroup example.