FILE / ScuroNeko/mtg

internal/utils/root_context.go

Исходный файл и его история в репозитории.
FILE 139db15e830f210f793d3c21b3430ba9ce4ca779
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
}