add sync wait cmd ctrl+c exit
This commit is contained in:
parent
52a05c3d0e
commit
4f977d21ef
13
cli/sync.go
13
cli/sync.go
@ -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):
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user