feat: listen for shutdown correctly
Closes #5 Closes #3 Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
9b84155265
commit
5c92bc8ee6
|
@ -3,6 +3,9 @@ package cli
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.numtide.com/numtide/treefmt/internal/cache"
|
||||
|
@ -10,7 +13,6 @@ import (
|
|||
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/juju/errors"
|
||||
"github.com/ztrue/shutdown"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
|
@ -33,9 +35,6 @@ func (f *Format) Run() error {
|
|||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// register shutdown hook
|
||||
shutdown.Add(cancel)
|
||||
|
||||
// read config
|
||||
cfg, err := format.ReadConfigFile(Cli.ConfigFile)
|
||||
if err != nil {
|
||||
|
@ -186,7 +185,13 @@ func (f *Format) Run() error {
|
|||
return cache.ChangeSet(ctx, Cli.TreeRoot, pathsCh)
|
||||
})
|
||||
|
||||
// shutdown.Listen(syscall.SIGINT, syscall.SIGTERM)
|
||||
// listen for shutdown and call cancel if required
|
||||
go func() {
|
||||
exit := make(chan os.Signal, 1)
|
||||
signal.Notify(exit, os.Interrupt, syscall.SIGTERM)
|
||||
<-exit
|
||||
cancel()
|
||||
}()
|
||||
|
||||
return eg.Wait()
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user