Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/util/signals/interrupt.go
John Smith 0bdd915f9a
Let net/http gracefully close
http.Server.Shutdown gracefully closes listeners/clients, we do not have to
do it ourselves. Making util/signals accept func() instead of io.Closer
allowed for the removal of network/closer.go and util/signals/closers.go.
2017-05-29 16:29:34 +10:00

35 lignes
665 o
Go

package signals
import (
"github.com/NyaaPantsu/nyaa/router"
"github.com/NyaaPantsu/nyaa/util/log"
"sync"
)
// registered interrupt callbacks.
// currently only used to gracefully close the server.
var intEvents struct {
lock sync.Mutex
funcs []func()
}
func OnInterrupt(fn func()) {
intEvents.lock.Lock()
intEvents.funcs = append(intEvents.funcs, fn)
intEvents.lock.Unlock()
}
func handleReload() {
log.Info("Got SIGHUP")
router.ReloadTemplates()
log.Info("reloaded templates")
}
// handle interrupt signal, platform independent
func interrupted() {
intEvents.lock.Lock()
for _, fn := range intEvents.funcs {
fn()
}
intEvents.lock.Unlock()
}