Files
kubeshark/utils/wait.go
M. Mert Yildiran 86fd616b84 Use github.com/rs/zerolog for logging (#1255)
* Use `github.com/rs/zerolog` for logging

* Use `github.com/rs/zerolog` for logging (continue)

* Add `debug` flag

* Remove `github.com/op/go-logging` dependency completely

* Fix linter
2022-11-29 03:48:20 +03:00

27 lines
566 B
Go

package utils
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/rs/zerolog/log"
)
func WaitForFinish(ctx context.Context, cancel context.CancelFunc) {
log.Debug().Msg("Waiting to finish...")
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
// block until ctx cancel is called or termination signal is received
select {
case <-ctx.Done():
log.Debug().Msg("Context done.")
break
case <-sigChan:
log.Debug().Msg("Got a termination signal, canceling execution...")
cancel()
}
}