FILE / ScuroNeko/mtg

internal/utils/root_context.go

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