liveBook · Manning

Context.Done

Context.Done is a method that returns a channel closed when a context is canceled or reaches its deadline.

How 2 Manning books explain it

100 Go Mistakes and How to Avoid Them

The Done method returns a channel that is closed when a context's cancellation or deadline signal occurs.

How it is used
Makes channel-based functions stop when cancellation or a deadline signals that their work should end.
How deep it goes
Explains channel closure, cancellation errors, deadline errors, and select-based protection for blocking sends and receives.
Examples
Uses a message-receiving loop plus separate cancellation-aware send and receive operations.
What you can do after
Apply it via Go select statements to make channel operations respond to cancellation and deadlines.

Read how 100 Go Mistakes and How to Avoid Them explains Context.Done →

Learn Go with Pocket-Sized Projects

context.Context.Done is a method that returns a channel closed when the context is canceled or reaches its deadline.

How it is used
Coordinates response handling with cancellation and deadlines in APIs, database calls, and other timeout-aware operations.
How deep it goes
Explains channel closure and select-based handling, then demonstrates child-context timeouts and cancellation testing.
Examples
Uses a backend response select, a timed database call, and a mock that waits for ctx.Done().
What you can do after
Apply it via Go select statements to stop waiting when a context is canceled or its deadline expires.

Read how Learn Go with Pocket-Sized Projects explains Context.Done →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.