Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cond ¶
Cond implements a condition variable. Typically sync.Cond should be preferred. However, this implementation supports cancellable waits.
func (*Cond) Broadcast ¶
func (c *Cond) Broadcast()
Broadcast wakes all goroutines waiting on c.
It is allowed but not required for the caller to hold c.L during the call.
func (*Cond) Signal ¶
func (c *Cond) Signal()
Signal wakes one goroutine waiting on c, if there is any.
It is allowed but not required for the caller to hold c.L during the call.
Signal() does not affect goroutine scheduling priority; if other goroutines are attempting to lock c.L, they may be awoken before a "waiting" goroutine.
func (*Cond) Wait ¶
Wait atomically unlocks c.L and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. Unlike in other systems, Wait cannot return unless awoken by Cond.Broadcast, Cond.Signal, or due to the context being cancelled.
Because c.L is not locked while Wait is waiting, the caller typically cannot assume that the condition is true when Wait returns, even if the returned value is nil. Instead, the caller should Wait in a loop:
c.L.Lock()
defer c.L.Unlock()
for !condition() {
if err := c.Wait(ctx); err != nil {
return err
}
}
... make use of condition ...
type ProgressSubscription ¶
ProgressSubscription allows a caller to subscribe to progress updates.
func NewProgressSubscription ¶
func NewProgressSubscription[T cmp.Ordered](initialProgress T) *ProgressSubscription[T]
NewProgressSubscription returns a new ProgressSubscription with the given initial progress.
func (*ProgressSubscription[T]) SetProgress ¶
func (ps *ProgressSubscription[T]) SetProgress(progress T)
SetProgress updates the progress of this ProgressSubscription to the given value. This will unblock any calls to WaitForProgress that are waiting for a progress value above the given value. It is assumed that progress values are monotonically increasing.
func (*ProgressSubscription[T]) WaitForProgress ¶
func (ps *ProgressSubscription[T]) WaitForProgress(ctx context.Context, pos T) error
WaitForProgress blocks until the progress of this ProgressSubscription is above the given value, or until the given context is cancelled.