signal

package module
v1.0.0 Latest Latest
Warning

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

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

README

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 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)

Types

This section is empty.

Jump to

Keyboard shortcuts

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