github.com/ifnotnil/daemon
Package daemon encapsulates the core functionality required for running an application as a daemon or service, and it ensures a graceful shutdown when stop conditions are met. Stop conditions: The shutdown can be initiated manually at any point by calling ShutDown() daemon's receiver function. Example usage: Context: The context provided by the daemon struct .CTX() should be passed downstream to the rest of the code. It will get cancelled by default after the shutdown callbacks are done or if it configured as a shutdown callback by passing daemon.CancelCTX in the Defer() function. Shutdown callbacks: Using the daemon function Defer(f ...func(context.Context)) you can register callback functions that will be called (in LIFO order) once the graceful shutdown is initiated. The context that is given to each shutdown callback is not the same with .CTX(). It will be the parentCTX with a separate timeout (shutdown grace period) depending on the configuration. Fatal errors channel: Daemon provides an error channel FatalErrorsChannel() chan<- error that can be used downstream to push errors that are considered catastrophic into it. Once an error received in this channel the daemon struct will initiate the graceful shutdown process.
proxy.golang.org
v0.0.3
7 months ago
3
Links
| Registry | proxy.golang.org |
| Source | Repository |
| Docs | Documentation |
| JSON API | View JSON |
| CodeMeta | codemeta.json |
Package Details
| PURL |
pkg:golang/github.com/ifnotnil/daemon
spec |
| License | MIT |
| Namespace | github.com/ifnotnil |
| First Release | 12 months ago |
| Last Synced | about 1 month ago |
Repository
| Stars | 0 on GitHub |
| Forks | 0 on GitHub |