Documentation ¶
Index ¶
- Variables
- func BackgroundWorker(name string, handler WorkerFunc, priority ...int) error
- func GetRunningBackgroundWorkers() []string
- func IsRunning() bool
- func IsStopped() bool
- func Run()
- func Shutdown()
- func ShutdownAndWait()
- func Start()
- type Daemon
- type OrderedDaemon
- func (d *OrderedDaemon) BackgroundWorker(name string, handler WorkerFunc, order ...int) error
- func (d *OrderedDaemon) GetRunningBackgroundWorkers() []string
- func (d *OrderedDaemon) IsRunning() bool
- func (d *OrderedDaemon) IsStopped() bool
- func (d *OrderedDaemon) Run()
- func (d *OrderedDaemon) Shutdown()
- func (d *OrderedDaemon) ShutdownAndWait()
- func (d *OrderedDaemon) Start()
- type WorkerFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrDaemonAlreadyStopped = errors.New("daemon was already stopped") ErrExistingBackgroundWorkerStillRunning = errors.New("existing background worker is still running") )
Errors for the daemon package
Functions ¶
func BackgroundWorker ¶
func BackgroundWorker(name string, handler WorkerFunc, priority ...int) error
BackgroundWorker adds a new background worker to the default daemon instance. Use shutdownOrderWorker to define in which shutdown order this particular background worker is shut down (higher = earlier).
func GetRunningBackgroundWorkers ¶
func GetRunningBackgroundWorkers() []string
GetRunningBackgroundWorkers gets the running background workers of the default daemon instance.
func IsRunning ¶
func IsRunning() bool
IsRunning checks whether the default daemon instance is running.
func IsStopped ¶
func IsStopped() bool
IsStopped checks whether the default daemon instance was stopped.
func Run ¶
func Run()
Run runs the default daemon instance and then waits for the daemon to shutdown.
func Shutdown ¶
func Shutdown()
Shutdown signals all background worker of the default daemon instance to shut down. This call doesn't await termination of the background workers.
func ShutdownAndWait ¶
func ShutdownAndWait()
ShutdownAndWait signals all background worker of the default daemon instance to shut down and then waits for their termination.
Types ¶
type Daemon ¶
type Daemon interface { // GetRunningBackgroundWorkers gets the running background workers. GetRunningBackgroundWorkers() []string // BackgroundWorker adds a new background worker to the daemon. // Use order to define in which shutdown order this particular // background worker is shut down (higher = earlier). BackgroundWorker(name string, handler WorkerFunc, order ...int) error // Start starts the daemon. Start() // Run runs the daemon and then waits for the daemon to shutdown. Run() // Shutdown signals all background worker of the daemon shut down. // This call doesn't await termination of the background workers. Shutdown() // Shutdown signals all background worker of the daemon to shut down and // then waits for their termination. ShutdownAndWait() // IsRunning checks whether the daemon is running. IsRunning() bool // IsStopped checks whether the daemon was stopped. IsStopped() bool }
Daemon specifies an interface to run background go routines.
type OrderedDaemon ¶
type OrderedDaemon struct {
// contains filtered or unexported fields
}
OrderedDaemon is an orchestrator for background workers. stopOnce ensures that the daemon can only be terminated once.
func (*OrderedDaemon) BackgroundWorker ¶
func (d *OrderedDaemon) BackgroundWorker(name string, handler WorkerFunc, order ...int) error
BackgroundWorker adds a new background worker to the daemon. Use order to define in which shutdown order this particular background worker is shut down (higher = earlier).
func (*OrderedDaemon) GetRunningBackgroundWorkers ¶
func (d *OrderedDaemon) GetRunningBackgroundWorkers() []string
GetRunningBackgroundWorkers gets the running background workers.
func (*OrderedDaemon) IsRunning ¶
func (d *OrderedDaemon) IsRunning() bool
IsRunning checks whether the daemon is running.
func (*OrderedDaemon) IsStopped ¶
func (d *OrderedDaemon) IsStopped() bool
IsStopped checks whether the daemon was stopped.
func (*OrderedDaemon) Run ¶
func (d *OrderedDaemon) Run()
Run runs the daemon and then waits for the daemon to shutdown.
func (*OrderedDaemon) Shutdown ¶
func (d *OrderedDaemon) Shutdown()
Shutdown signals all background worker of the daemon shut down. This call doesn't await termination of the background workers.
func (*OrderedDaemon) ShutdownAndWait ¶
func (d *OrderedDaemon) ShutdownAndWait()
ShutdownAndWait signals all background worker of the daemon to shut down and then waits for their termination.
type WorkerFunc ¶
type WorkerFunc = func(shutdownSignal <-chan struct{})
WorkerFunc is the function to run a worker accepting its shutdown signal handler channel.