Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on May 10, 2020. It is now read-only.
/onexitPublic archive

run functions on app exit (receiving os signal)

License

NotificationsYou must be signed in to change notification settings

workshop-depot/onexit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc

onexit

Package helps with running functions on app exit (receiving an OS signal), based on their priority.

Functions will be registtered with a priority and be called based on that priority - a priority queue is implemented by employing a heap.

The last statement ofmain() can be<-onexit.Done() which waits for all registered functions to run, before exit.

package mainimport ("github.com/dc0d/onexit")funcmain() {onexit.Register(Logout,100)onexit.Register(func() {println("\n") })// ...<-onexit.Done()}funcinit() {onexit.Register(SyncLogger,-100)}

Callingos.Exit(code) explicitly, will not triggeronexit to run registered functions. Because it causes the program to exit without waiting for anything. Instead, callonexit.ForceExit(code) which waits for all registered functions to execute and then callsos.Exit(code).

About

run functions on app exit (receiving os signal)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp