4 ms·
Question about contexts in general: is there a way to "guarantee" that contexts are used correctly by whoever is consuming my context? For example, if I call h
by memset 3y ago
Question about contexts in general: is there a way to "guarantee" that contexts are used correctly by whoever is consuming my context?
For example, if I call http.NewRequestWithContext(), how do I, as the caller, know that http is doing the "right thing" with that value, rather than ignoring it?
In the OP's example, intuitively it seems like an explicit Stop() function gives the caller explicit control of when to stop and that anyone implementing a Worker (if Worker were an interface) would know that the Stop() function should do cleanup.
However, if I only pass in a context when calling Run(), wouldn't it be easy for someone to ignore a deadline?
- deleted 3y ago[deleted]
- badrequest 3y agoMost of the time you accept a context because some downstream function requires it (i.e. I'm writing an HTTP client, and the `net/http` std lib functions require context for some part of it). You can have general confidence that the standard library will respect things like context deadlines, even if the wrappers that invoke that don't necessarily.