Documentation ¶
Overview ¶
Package contextcond provides a sync.Cond that has a WaitContext method.
Internally it's implemented using channels and mutexes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cond ¶
type Cond struct { // L is held while observing or changing the condition L sync.Locker // contains filtered or unexported fields }
Cond is like sync.Cond with a WaitContext method. Unlike sync.Cond, Cond must be initialized with NewCond.
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 ¶
func (c *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 Broadcast or Signal. Because c.L is not locked while Wait is waiting, the caller typically cannot assume that the condition is true when Wait returns. Instead, the caller should Wait in a loop.