FILE / ScuroNeko/mtg

internal/utils/root_context.go

Исходный файл и его история в репозитории.
FILE 008e17cdff2f6e21ba62c56f2c14e3f476c03a22
Files
mtg/internal/utils/root_context.go
T
2021-10-05 10:51:41 +03:00

27 lines
368 B
Go

//go:build !windows
// +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
}