mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-02-21 06:02:06 +00:00
* 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
27 lines
566 B
Go
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()
|
|
}
|
|
}
|