shutdown

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 2 Imported by: 4

README

Shutdown

This is a Go package providing a mechanism for signalling two-tier shutdown mechanics in asynchronous components.

This package is "complete" in the sense that no further development work is planned and any PRs proposing to expand its scope will be rejected. However, please continue to report bugs and feel free to raise PRs to address them.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 a "soft stop", 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 a "hard stop", 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 stopped, which is made by the component and can be used from outside to determine whether the component has finished terminating.

func NewSignaller

func NewSignaller() *Signaller

NewSignaller creates a new signaller.

func (*Signaller) HardStopChan

func (s *Signaller) HardStopChan() <-chan struct{}

HardStopChan returns a channel that will be closed when the signal to hard stop has been made.

func (*Signaller) HardStopCtx

func (s *Signaller) HardStopCtx(ctx context.Context) (context.Context, context.CancelFunc)

HardStopCtx returns a context.Context that will be terminated when either the provided context is cancelled or the signal to hard stop has been made.

func (*Signaller) HasStoppedChan

func (s *Signaller) HasStoppedChan() <-chan struct{}

HasStoppedChan returns a channel that will be closed when the signal that the component has stopped has been made.

func (*Signaller) HasStoppedCtx

func (s *Signaller) HasStoppedCtx(ctx context.Context) (context.Context, context.CancelFunc)

HasStoppedCtx returns a context.Context that will be cancelled when either the provided context is cancelled or the signal that the component has stopped has been made.

func (*Signaller) IsHardStopSignalled

func (s *Signaller) IsHardStopSignalled() bool

IsHardStopSignalled returns true if the signaller has received the signal to hard stop.

func (*Signaller) IsHasStoppedSignalled

func (s *Signaller) IsHasStoppedSignalled() bool

IsHasStoppedSignalled returns true if the signaller has received the signal that the component has stopped.

func (*Signaller) IsSoftStopSignalled

func (s *Signaller) IsSoftStopSignalled() bool

IsSoftStopSignalled returns true if the signaller has received the signal to soft stop.

func (*Signaller) SoftStopChan

func (s *Signaller) SoftStopChan() <-chan struct{}

SoftStopChan returns a channel that will be closed when the signal to soft or hard stop has been made.

func (*Signaller) SoftStopCtx

func (s *Signaller) SoftStopCtx(ctx context.Context) (context.Context, context.CancelFunc)

SoftStopCtx returns a context.Context that will be terminated when either the provided context is cancelled or the signal to soft or hard stop has been made.

func (*Signaller) TriggerHardStop

func (s *Signaller) TriggerHardStop()

TriggerHardStop signals to the owner of this Signaller that it should terminate right now regardless of any in progress tasks.

func (*Signaller) TriggerHasStopped

func (s *Signaller) TriggerHasStopped()

TriggerHasStopped is a signal made by the component that it and all of its owned resources have terminated.

func (*Signaller) TriggerSoftStop

func (s *Signaller) TriggerSoftStop()

TriggerSoftStop 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL