signal

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 4 Imported by: 3

README

Build Status Maintainability Test Coverage

signal

This repository provides helpers with signals

Subscriber

Signal subscriber that allows you to attach a callback to an os.Signal notification.

Useful to react to any os.Signal.

It returns an unsubscribe function that can gracefully stop some http server and clean allocated object

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

func Subscribe(callback func(os.Signal), signals ...os.Signal) func()

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)

func SubscribeWithKiller added in v1.1.0

func SubscribeWithKiller(callback func(os.Signal), signals ...os.Signal) func()

This helper allows you to enable killer subscriber and subscribe your callback at once

Types

This section is empty.

Jump to

Keyboard shortcuts

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