update commands when running in supervised mode

This commit is contained in:
A.Unger
2021-03-10 11:10:46 +01:00
parent 25909d5923
commit 4e37d4a2f6
72 changed files with 1547 additions and 803 deletions
+22
View File
@@ -0,0 +1,22 @@
package sync
import (
"context"
"os"
"os/signal"
"github.com/oklog/run"
)
// Trap listens to interrupt signals and handles context cancellation and channel closing on a group run.
func Trap(gr *run.Group, cancel context.CancelFunc) {
stop := make(chan os.Signal, 1)
gr.Add(func() error {
signal.Notify(stop, os.Interrupt)
<-stop
return nil
}, func(err error) {
close(stop)
cancel()
})
}