Documentation ¶
Overview ¶
Package sync contains a mutex that can be used in a select statement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyClosedError ¶
IsAlreadyClosedError checks whether an error is an AlreadyClosedError.
Types ¶
type Closer ¶
type Closer struct {
// contains filtered or unexported fields
}
Closer is a utility type for implementing an "onclose" event. It supports registering handlers, waiting for the event, and status checking. A default-initialised Closer is a valid value.
func (*Closer) Close ¶
Close executes all registered callbacks. If Close was already called before, returns an AlreadyClosedError, otherwise, returns nil.
func (*Closer) Closed ¶
func (c *Closer) Closed() <-chan struct{}
Closed returns a channel to be used in a select statement.
func (*Closer) OnClose ¶
OnClose registers the passed callback to be executed when the Closer is closed. If the closer is already closed, the callback will be ignored.
Returns true if the callback was successfully registered and false if the closer was already closed and callback was ignored.
func (*Closer) OnCloseAlways ¶
OnCloseAlways registers the passed callback to be executed when the Closer is closed. If the closer is already closed, the callback will be executed immediately.
Returns true if the callback was successfully registered and false if the closer was already closed and callback was executed immediately.
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex is a replacement of the standard mutex type. It supports the additional TryLock() function, as well as a variant that can be used in a select statement.
func (*Mutex) TryLock ¶
TryLock tries to lock the mutex without blocking. Returns whether the mutex was acquired.
func (*Mutex) TryLockCtx ¶
TryLockCtx tries to lock the mutex within a timeout provided by a context. For an instant timeout, a nil context has to be passed. Returns whether the mutex was acquired.
type Signal ¶
type Signal struct {
// contains filtered or unexported fields
}
Signal is a lightweight reusable signal that can be waited on. It can be used to notify coroutines. Coroutines waiting for the signal will be notified once it is triggered, but coroutines starting to wait after triggering will not be notified by the same operation. This means it can be used to repeatably notify coroutines.
func (*Signal) Done ¶
func (s *Signal) Done() <-chan struct{}
Done returns a channel that will be written to when the signal is next notified. After reading from the returned channel once, the channel should be discarded, and a new channel should be retrieved via a new call to Done.
func (*Signal) Signal ¶
func (s *Signal) Signal()
Signal wakes up a single coroutine, if any are waiting.
type WaitGroup ¶
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup is an analog to sync.WaitGroup but also features WaitCh, which exposes a channel that is closed once the wait group is fulfilled, and WaitCtx, which allows waiting until either the wait group is fulfilled or the provided context expires.