Documentation ¶
Overview ¶
Package signalcontext creates context.Contexts that cancel on os.Signals.
ctx, cancel := signalcontext.OnInterrupt() defer cancel()
Deprecated: Use signal.NotifyContext instead.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OnInterrupt
deprecated
func OnInterrupt() (context.Context, context.CancelFunc)
OnInterrupt creates a new context that cancels on SIGINT or SIGTERM.
Deprecated: Use signal.NotifyContext instead.
Example ¶
ctx, cancel := signalcontext.OnInterrupt() defer cancel() s := &http.Server{ Addr: ":8080", } go func() { if err := s.ListenAndServe(); err != nil { log.Fatal(err) } }() // Wait for CTRL+C <-ctx.Done() // Stop the server shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := s.Shutdown(shutdownCtx); err != nil { log.Fatal(err) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.