-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
21 lines (19 loc) · 731 Bytes
/
context.go
File metadata and controls
21 lines (19 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package web
import (
"context"
"os"
"os/signal"
"syscall"
)
// CoreContext provides a context that is canceled when an interrupt signal is received.
//
// This function creates a context that listens for operating system signals such as
// `os.Interrupt` and `syscall.SIGTERM`. It is useful for gracefully shutting down
// applications when these signals are received.
//
// Note:
// - This is defined as a variable to allow users of the package to override it if needed.
// For example, users may want to use a different signal or context for testing or customization.
var CoreContext = func() (context.Context, context.CancelFunc) {
return signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
}