all repos — honk @ 2e2387812feb9045c43158b6c220b7fca5309bcd

my fork of honk

make sure everything is saved before the end of the world
Ted Unangst tedu@tedunangst.com
Fri, 08 Nov 2019 17:43:32 -0500
commit

2e2387812feb9045c43158b6c220b7fca5309bcd

parent

02a87b38648808b8b6a9cba488633f6dca5d1b12

1 files changed, 33 insertions(+), 0 deletions(-)

jump to
M web.goweb.go

@@ -26,6 +26,7 @@ notrand "math/rand"

"net/http" "net/url" "os" + "os/signal" "regexp" "sort" "strconv"

@@ -924,6 +925,11 @@ go savetracks(tracks)

tracks = make(map[string][]string) } sleeper.Reset(timeout) + case <-endoftheworld: + if len(tracks) > 0 { + savetracks(tracks) + } + readyalready <- true } } }

@@ -2017,6 +2023,32 @@ http.Error(w, "unknown action", http.StatusNotFound)

} } +var endoftheworld = make(chan bool) +var readyalready = make(chan bool) + +func enditall() { + sig := make(chan os.Signal) + signal.Notify(sig, os.Interrupt) + <-sig + count := 0 + log.Printf("stopping...") +sendloop: + for { + select { + case endoftheworld <- true: + count++ + default: + break sendloop + } + } + log.Printf("waiting...") + for i := 0; i < count; i++ { + <-readyalready + } + log.Printf("apocalypse") + os.Exit(0) +} + func serve() { db := opendatabase() login.Init(db)

@@ -2025,6 +2057,7 @@ listener, err := openListener()

if err != nil { log.Fatal(err) } + go enditall() go redeliverator() go tracker()