Files
akvorado/common/daemon/lifecycle.go
2022-04-01 20:21:53 +02:00

23 lines
546 B
Go

package daemon
import (
"sync"
)
// lifecycleComponent is the lifecycle part of a component.
type lifecycleComponent struct {
terminateChannel chan struct{}
terminateOnce sync.Once
}
// Terminated will return a channel that will be closed when the daemon
// needs to terminate.
func (c *lifecycleComponent) Terminated() <-chan struct{} {
return c.terminateChannel
}
// Terminate should be called to request termination of a daemon.
func (c *lifecycleComponent) Terminate() {
c.terminateOnce.Do(func() { close(c.terminateChannel) })
}