Documentation ¶
Index ¶
- func MaximumShutdownWait() time.Duration
- type Signaller
- func (s *Signaller) CloseAtLeisure()
- func (s *Signaller) CloseAtLeisureChan() <-chan struct{}
- func (s *Signaller) CloseAtLeisureCtx(ctx context.Context) (context.Context, context.CancelFunc)
- func (s *Signaller) CloseNow()
- func (s *Signaller) CloseNowChan() <-chan struct{}
- func (s *Signaller) CloseNowCtx(ctx context.Context) (context.Context, context.CancelFunc)
- func (s *Signaller) HasClosed() bool
- func (s *Signaller) HasClosedChan() <-chan struct{}
- func (s *Signaller) HasClosedCtx(ctx context.Context) (context.Context, context.CancelFunc)
- func (s *Signaller) ShouldCloseAtLeisure() bool
- func (s *Signaller) ShouldCloseNow() bool
- func (s *Signaller) ShutdownComplete()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaximumShutdownWait ¶
MaximumShutdownWait is a magic number determining the maximum length of time that a component should be willing to wait for a child to finish shutting down before it can give up and exit.
This wait time is largely symbolic, if a component blocks for anything more than a few minutes then it has failed in its duty to gracefully terminate.
However, it's still necessary for components to provide some measure of time that they're willing to wait for with the current mechanism (WaitForClose), therefore we provide a very large duration, and since this is a magic number I've defined it once and exposed as a function, allowing us to more easily identify these cases and refactor them in the future.
Types ¶
type Signaller ¶
type Signaller struct {
// contains filtered or unexported fields
}
Signaller is a mechanism owned by components that support graceful shut down and is used as a way to signal from outside that any goroutines owned by the component should begin to close.
Shutting down can happen in two tiers of urgency, the first is to terminate "at leisure", meaning if you're in the middle of something it's okay to do that first before terminating, but please do not commit to new work.
The second tier is immediate, where you need to clean up resources and terminate as soon as possible, regardless of any tasks that you are currently attempting to finish.
Finally, there is also a signal of having closed down, which is made by the component and can be used from outside to determine whether the component has finished terminating.
func (*Signaller) CloseAtLeisure ¶
func (s *Signaller) CloseAtLeisure()
CloseAtLeisure signals to the owner of this Signaller that it should terminate at its own leisure, meaning it's okay to complete any tasks that are in progress but no new work should be started.
func (*Signaller) CloseAtLeisureChan ¶
func (s *Signaller) CloseAtLeisureChan() <-chan struct{}
CloseAtLeisureChan returns a channel that will be closed when the signal to shut down either at leisure or immediately has been made.
func (*Signaller) CloseAtLeisureCtx ¶
CloseAtLeisureCtx returns a context.Context that will be terminated when either the provided context is cancelled or the signal to shut down either at leisure or immediately has been made.
func (*Signaller) CloseNow ¶
func (s *Signaller) CloseNow()
CloseNow signals to the owner of this Signaller that it should terminate right now regardless of any in progress tasks.
func (*Signaller) CloseNowChan ¶
func (s *Signaller) CloseNowChan() <-chan struct{}
CloseNowChan returns a channel that will be closed when the signal to shut down immediately has been made.
func (*Signaller) CloseNowCtx ¶
CloseNowCtx returns a context.Context that will be terminated when either the provided context is cancelled or the signal to shut down immediately has been made.
func (*Signaller) HasClosed ¶
HasClosed returns true if the signaller has received the signal that the component has terminated.
func (*Signaller) HasClosedChan ¶
func (s *Signaller) HasClosedChan() <-chan struct{}
HasClosedChan returns a channel that will be closed when the signal that the component has terminated has been made.
func (*Signaller) HasClosedCtx ¶
HasClosedCtx returns a context.Context that will be cancelled when either the provided context is cancelled or the signal that the component has shut down has been made.
func (*Signaller) ShouldCloseAtLeisure ¶
ShouldCloseAtLeisure returns true if the signaller has received the signal to shut down at leisure or immediately.
func (*Signaller) ShouldCloseNow ¶
ShouldCloseNow returns true if the signaller has received the signal to shut down immediately.
func (*Signaller) ShutdownComplete ¶
func (s *Signaller) ShutdownComplete()
ShutdownComplete is a signal made by the component that it and all of its owned resources have terminated.