8000 GitHub - cloudproud/graceful: Gracefully shutdown anything
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cloudproud/graceful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graceful

Graceful is a tiny but powerful package to ensures your application shuts down cleanly, allowing registered closers to complete their tasks before exiting.

Force Shutdowns

Force shutdown are possible in case a graceful shutdown fails. If you send a kill signal (Ctrl+C) once, the application begins its shutdown process, allowing all registered closers to complete. If send a kill signal (Ctrl+C) again, the application will force quit immediately.

package main

import (
    "context"
    "github.com/cloudproud/graceful"
)

func main() {
    ctx := graceful.NewContext(context.Background())

    go ctx.Closer(func() {
        // gracefully shutdown connection
    })

    var err error
    if err != nil {
        ctx.Shutdown() // initiates a graceful shutdown of the application due to a critical error
    }

    ctx.AwaitKillSignal()
}

About

Gracefully shutdown anything

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0