qbtrade/pkg/cmd/cmdutil/signal.go

28 lines
382 B
Go
Raw Normal View History

2024-06-27 14:42:38 +00:00
package cmdutil
import (
"context"
"os"
"os/signal"
"github.com/sirupsen/logrus"
)
func WaitForSignal(ctx context.Context, signals ...os.Signal) os.Signal {
var sigC = make(chan os.Signal, 1)
signal.Notify(sigC, signals...)
defer signal.Stop(sigC)
select {
case sig := <-sigC:
logrus.Warnf("%v", sig)
return sig
case <-ctx.Done():
return nil
}
return nil
}