z-go-context

Installation
SKILL.md

context.Context

Quick reference

Situation Use
Entry point (main, init, test body) context.Background()
Function needs ctx but caller doesn't supply one yet context.TODO()
HTTP handler r.Context()
Manual cancellation context.WithCancel(parent)
Relative timeout context.WithTimeout(parent, d)
Absolute deadline context.WithDeadline(parent, t)
Background work must outlive request (Go 1.21+) context.WithoutCancel(ctx)

* context.AfterFunc(ctx, fn) (Go 1.21+) runs fn in its own goroutine when ctx is done — an alternative to WithoutCancel + an explicit select for pure cleanup. Zero use in practice so far; reach for it only if the select pattern below doesn't fit.

Core rules

Installs
14
First Seen
Jul 2, 2026