Skip to content

lingdor/gexit

Repository files navigation

gexit (graceful exit)

graceful,safty exit for your golang program.

demo

/

go get github.com/lingdor/gexit

init module code :

ctx:=context.Background()
gexit.InitGExit(ctx)

exit func callback

gexit.AddPreExitFunc(func(){
	fmt.Println("pre exit invoked!")
})

Context run

ctx:=gexit.GetContext()  //get exit context
for{
    select{
        case <-ctx.Done(): //when exit event
            fmt.Printf("goroutine %d at done!\n",num)
            return
        default:break
    }
    //normal program
}

gexit-example

https://github.com/lingdor/gexit-example

#contact

mailto: [email protected]