Documentation ¶
Index ¶
- func DoWithTimeout(w Waitable, action func(), timeout time.Duration) bool
- func IsDone(w Waitable) bool
- func Wait(w Waitable)
- func WaitWithTimeout(w Waitable, timeout time.Duration) bool
- type Signal
- func (s *Signal) Done() <-chan struct{}
- func (s *Signal) IsDone() bool
- func (s *Signal) Reset() bool
- func (s *Signal) Signal() bool
- func (s *Signal) SignalWhen(triggerCond Waitable, cancelCond Waitable) bool
- func (s *Signal) Snapshot() WaitableChan
- func (s *Signal) Wait()
- func (s *Signal) WaitC() WaitableChan
- type Waitable
- type WaitableChan
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoWithTimeout ¶
DoWithTimeout performs the action as soon as the waitable is done. It gives up and returns after timeout, and returns a bool indicating whether the action was performed or not.
Types ¶
type Signal ¶
type Signal struct {
// contains filtered or unexported fields
}
Signal implements a signalling facility. Unlike sync.Cond, it is based on channels and can hence be used in `select` statements. There are two ways to instantiate a Signal. The preferred way is by calling `NewSignal()`, which will return a signal that is not triggered. Alternatively, the zero-value can be used to instantiate a signal in triggered condition, which is not what you usually want. To reset it to the non-triggered state, call `Reset()`. Similarly to `sync.(RW)Mutex` and `sync.Cond`, a signal should not be copied once used.
func (*Signal) Done ¶
func (s *Signal) Done() <-chan struct{}
Done returns a channel that is closed when this signal was triggered.
func (*Signal) IsDone ¶
IsDone checks if the signal was triggered. It is a slightly more efficient alternative to calling `IsDone(s)`.
func (*Signal) Reset ¶
Reset resets the signal to the non-triggered state, if necessary. The return value indicates whether a reset was actually performed (i.e., the signal was triggered). It returns false if the signal was not in the triggered state.
func (*Signal) Signal ¶
Signal triggers the signal. The return value indicates whether the signal was actually triggered. It returns false if the signal was already in the triggered state.
func (*Signal) SignalWhen ¶
SignalWhen triggers this signal when the given trigger condition is satisfied. It returns as soon as either this signal is triggered (either by this function or another goroutine), or cancelCond is triggered (in which case the signal will not be triggered). CAREFUL: This function blocks; if you do not want this, invoke it in a goroutine.
func (*Signal) Snapshot ¶
func (s *Signal) Snapshot() WaitableChan
Snapshot returns a WaitableChan that observers will only see triggering once, i.e., if this signal is triggered (or has been triggered) and then `Reset()` is called, subsequent calls to `Done()` on the returned object will still see a triggered channel.
func (*Signal) Wait ¶
func (s *Signal) Wait()
Wait waits for the signal to be triggered. It is a slightly more efficient and convenient alternative to calling `Wait(s)`.
func (*Signal) WaitC ¶
func (s *Signal) WaitC() WaitableChan
WaitC returns a WaitableChan for this signal.
type Waitable ¶
type Waitable interface {
Done() <-chan struct{}
}
Waitable is a generic interface for things that can be waited upon. The method `Done` returns a channel that, when closed, signals that whatever condition is represented by this waitable is satisfied. Note: The name `Done` was chosen such that `context.Context` conforms to this interface.
type WaitableChan ¶
type WaitableChan <-chan struct{}
WaitableChan is an alias around a `<-chan struct{}` that returns itself in its `Done` method.
func (WaitableChan) Done ¶
func (c WaitableChan) Done() <-chan struct{}
Done returns the channel itself.