Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

kilianpaquier/exithandler

Repository files navigation

exithandler

Archive note: Just copy/paste the related code listening to context signal 😉.

GitHub Actions GitHub Release GitHub Issues GitHub License Coverage Go Version Go Report Card


How to use ?

go get -u github.com/kilianpaquier/exithandler@latest

Features

The exithandler package exposes two useful functions to handle program terminations:

The first one is Handle which will blocked on SIGINT and SIGTERM signals until one of those are sent and then executes the provided function.

func main() {
    // some things to be defined

    go exithandler.Handle(ctx, func(context.Context) {
        // some things to close or execute when the program terminates
    })
}

The second one is HandleFunc which does the exact same thing, the only difference is that it returns the function which will wait and does not wait directly (as provided in below example).

func main() {
    // some things to be defined

    exithandler := exithandler.HandleFunc(ctx, func(context.Context) {
        // some things to close or execute when the program terminates
    })

    // other things to do

    exithandler()
}

Contributors 2

  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy