https://github.com/kcmerrill/shutdown.go
Shutdown your subroutines in priority order.
https://github.com/kcmerrill/shutdown.go
Last synced: 3 months ago
JSON representation
Shutdown your subroutines in priority order.
- Host: GitHub
- URL: https://github.com/kcmerrill/shutdown.go
- Owner: kcmerrill
- Created: 2016-03-01T03:50:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-01T18:36:42.000Z (over 9 years ago)
- Last Synced: 2025-01-26T17:11:21.385Z (5 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Shutdown.go
A really simple library to help handle the registring of subroutines in go(in priority order)#Example Code
```
package mainimport (
"fmt"
"github.com/kcmerrill/shutdown.go"
"syscall"
"time"
)func main() {
/* Start our application */
fmt.Println("Listening for shutdown ...")/* simulate a shutdown.Now() */
go DoSomethingToTriggerAShutdown()
for x := 10000; x >= 0; x-- {
go worker(x)
}/* Simulate a timeout */
//shutdown.Timeout("10m")
//shutdown.WaitFor(syscall.SIGINT, syscall.SIGTERM)
shutdown.WaitForTimeout("10m", syscall.SIGINT, syscall.SIGTERM) // this is the same as the above two lines
fmt.Println("\nShutting down ...")
}func worker(id int) {
/* Wait for this worker to finish, with a high priority(the lower the number, the faster the shutdown */
worker := shutdown.WaitForMe(id)/* You'd typically put this into your select {} */
<-worker.Stop()/* Tell the world we are ready to shutdown */
worker.Finished()
}func DoSomethingToTriggerAShutdown() {
<-time.After(30 * time.Second)
fmt.Println("Shutdown() triggered")
shutdown.Now()
}
```