add sync wait cmd ctrl+c exit

This commit is contained in:
wanghui 2019-11-15 16:54:32 +08:00
parent 52a05c3d0e
commit 4f977d21ef

View File

@ -2,6 +2,9 @@ package cli
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
cid "github.com/ipfs/go-cid"
@ -64,6 +67,9 @@ var syncWaitCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
sigChan := make(chan os.Signal, 2)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
for {
ss, err := napi.SyncState(ctx)
if err != nil {
@ -81,7 +87,12 @@ var syncWaitCmd = &cli.Command{
return nil
}
time.Sleep(1 * time.Second)
select {
case <-sigChan:
fmt.Println("\nExit by user")
return nil
case <-time.After(1 * time.Second):
}
}
},
}