CTX is Key!
summary
Context.Context represents three fields: cancellation boolean, deadline/timeout and opaque key values, and it actually propagates cancellation and timeouts across RPCs so a root 30 second timeout cancels all downstream calls while a front end can set a 5 second subtimeout for its children. API calls are WithCancel WithDeadline WithTimeout WithValue plus Background/TODO which return never canceling empty parents. Best practices shown: always defer cancel, shorten subdeadlines to reserve time, use typed package keys for creds, and use errgroup/select on ctx.Done to stop work early.
AI-written summary · about
chapters (13)
- 0:00Intro
- 1:05context is a common package
- 5:03Timeouts
- 8:17Hmm values seem pretty flexible...
- 10:52Naturally, contexts form a tree
- 13:00What is the API of a Context object
- 14:27Inside Context's implementation
- 16:35This forces that "tree" behavior
- 20:01context go code
- 21:31Create cancel
- 22:18Deadline - shortening
- 24:14Values - authorization lookup toy example
- 25:18Common Packages
related talks
32mHow to correctly use package context
50mThe context package internals
26mA Beginners Guide to Context
20m"Demystifying Context Values"
27mProduction Ready Concurrency
55mCharting the uncharted: Discovering and evolving bounded contexts
22mType. Context.
35m"Rush Tactics: Writing Go Code You Won’t Regret Later"
