Hi,

Are there any common patterns that standard and 3rd party library functions
use to implement cancelling a context passed to it? I have looked at the
source of exec.CommandContext and it starts the process and spawns a
goroutine that kills the process when ctx.Done() is closed. That looks
simple enough.

It seems to me that the key to implementing cancellation enabled function
is to look at specific points inside the function where ctx.Done() is
checked for. As an example, if I want to create a cancellable function that
reads lines from a file, would select'ing on ctx.Done() be a good place?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA_NO6jsxELqtVY%3DnAsKdOEgphrF4tU0p%3DH3aAOd4kMdoFBSEg%40mail.gmail.com.

Reply via email to