aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/signals
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
commitfc8c5fdce62fb229202659408798a7b6c98f6e8b (patch)
tree7554f80e50de4af6fd255afa7c21bcdd58a7af34 /cli/internal/signals
parentdd84b9d64fb98746a230cd24233ff50a562c39c9 (diff)
downloadHydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.tar.gz
HydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.zip
Diffstat (limited to 'cli/internal/signals')
-rw-r--r--cli/internal/signals/signals.go60
1 files changed, 0 insertions, 60 deletions
diff --git a/cli/internal/signals/signals.go b/cli/internal/signals/signals.go
deleted file mode 100644
index 8634144..0000000
--- a/cli/internal/signals/signals.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package signals
-
-import (
- "os"
- "os/signal"
- "sync"
- "syscall"
-)
-
-// Watcher watches for signals delivered to this process and provides
-// the opportunity for turbo to run cleanup
-type Watcher struct {
- doneCh chan struct{}
- closed bool
- mu sync.Mutex
- closers []func()
-}
-
-// AddOnClose registers a cleanup handler to run when a signal is received
-func (w *Watcher) AddOnClose(closer func()) {
- w.mu.Lock()
- defer w.mu.Unlock()
- w.closers = append(w.closers, closer)
-}
-
-// Close runs the cleanup handlers registered with this watcher
-func (w *Watcher) Close() {
- w.mu.Lock()
- defer w.mu.Unlock()
- if w.closed {
- return
- }
- w.closed = true
- for _, closer := range w.closers {
- closer()
- }
- w.closers = nil
- close(w.doneCh)
-}
-
-// Done returns a channel that will be closed after all of the cleanup
-// handlers have been run.
-func (w *Watcher) Done() <-chan struct{} {
- return w.doneCh
-}
-
-// NewWatcher returns a new Watcher instance for watching signals.
-func NewWatcher() *Watcher {
- // TODO: platform specific signals to watch for?
- signalCh := make(chan os.Signal, 1)
- signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
- w := &Watcher{
- doneCh: make(chan struct{}),
- }
- go func() {
- <-signalCh
- w.Close()
- }()
- return w
-}