Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KillerSubscriber ¶ added in v1.1.0
func KillerSubscriber() func()
This is a simple signal subscriber that kills program
It kills application when os.Kill or 2 interrupt signals are received ¶
Application gracefully stopped example:
defer signal.SubscribeWithKiller(func(signal os.Signal) {
// here you can implement your application stopping steps
}, os.Interrupt, syscall.SIGTERM)()
Final user can now CTRL-C to stop your app gracefully and if CTRL-C is stroked a second time it is gonna kill the application
func Subscribe ¶
This is a really simple signal subscriber Signal subscriber that allows you to attach a callback to an `os.Signal` notification. Usefull to react to any os.Signal. It returns an `unsubscribe` function that stops the goroutine and clean allocated object
Example:
unsubscriber := signal.Subscribe(func(s os.Signal) {
fmt.Println("process as been asked to be stopped")
}, os.SIGSTOP)
call "unsubscriber()" in order to detach your callback and clean memory
if no 2nd arg is passed, the `callback` func will be called everytime an os.Signal is triggered signal.subscribe(func(s os.Signal) {fmt.Println("called for any signal")})
/!\ CAUTION /!\ If you call it with second arg to `nil`, no signal will be listened signal.subscribe(func(s os.Signal) {fmt.Println("NEVER BE CALLED")}, nil)
Types ¶
This section is empty.