go/doc/next/6-stdlib/99-minor/os
Filippo Valsorda c1b7112af8 os/signal: make NotifyContext cancel the context with a cause
This is especially useful when combined with the nesting semantics of
context.Cause, and with errgroup's use of CancelCauseFunc.

For example, with the following code

	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
	defer stop()
	serveGroup, ctx := errgroup.WithContext(ctx)

calling context.Cause(ctx) after serveGroup.Wait() will return either
"interrupt signal received" (if that happens first) or the error from
serveGroup.

Change-Id: Ie181f5f84269f6e39defdad2d5fd8ead6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/721700
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-11-20 13:01:32 -08:00
..
signal os/signal: make NotifyContext cancel the context with a cause 2025-11-20 13:01:32 -08:00
70352.md os: add (*Process).WithHandle 2025-09-15 12:17:42 -07:00
73676.md os,syscall: pass file flags to CreateFile on Windows 2025-08-29 07:25:08 -07:00