use ctx.Done() to exit

This commit is contained in:
wanghui 2019-11-16 14:11:00 +08:00
parent 4f977d21ef
commit 0af9692072

View File

@ -2,9 +2,6 @@ package cli
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
cid "github.com/ipfs/go-cid"
@ -67,9 +64,6 @@ 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 {
@ -88,7 +82,7 @@ var syncWaitCmd = &cli.Command{
}
select {
case <-sigChan:
case <-ctx.Done():
fmt.Println("\nExit by user")
return nil
case <-time.After(1 * time.Second):