FILE / ScuroNeko/mtg

internal/utils/root_context.go

Исходный файл и его история в репозитории.
FILE b3112c5c6714dd04a4b7f1bd6939bebebd4284bc
Files
mtg/internal/utils/root_context.go
T
2021-04-02 21:27:34 +03:00

26 lines
348 B
Go

// +build !windows
package utils
import (
"context"
"os"
"os/signal"
"syscall"
)
func RootContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
for range sigChan {
cancel()
}
}()
return ctx
}