Skip to content

Glossary: Go Beyond the Basics

WithTimeout / WithCancel

Also written: context.WithTimeout, context.WithCancel, cancel

Each makes a child context plus a `cancel` function. `WithTimeout` ends after a time, and `WithCancel` ends only when you call `cancel`, which you should always do, usually with `defer`.

Where the book teaches it

Related terms

context (context.Context)ctx.Done()