Skip to content

Go OS signals handler for graceful services shutdown

Notifications You must be signed in to change notification settings

eventials/goawaysignals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

goawaysignals

Go OS signals handler

About

goawaysignals handles SIGHUP, SIGINT, SIGTERM, SIGQUIT and then waits for the registered async functions to return before handing back the control to the callee. This helps you to achieve graceful shutdown on many kinds of services.

How to use

package main

import (
	"fmt"

	"github.com/eventials/goawaysignals"
)

func main() {
	// fake services that need graceful shutdown.
	producer := NewExampleProducer()
	consumer := NewExampleConsumer()

	goawaysignals.Async(func() { <-producer.NotifyClose() })
	goawaysignals.Async(func() { <-consumer.NotifyClose() })

	goawaysignals.AfterSignal(func() {
		producer.Close()
		consumer.Close()
	})

	goawaysignals.Wait()
	fmt.Println("Exiting...")
}

If you need to exit before an OS signal, you can call goawaysignals.Close() and still provide graceful shutdown to your services.

About

Go OS signals handler for graceful services shutdown

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages