On Tue, Jan 11, 2022 at 12:15 PM 'Axel Wagner' via golang-nuts
<golang-nuts@googlegroups.com> wrote:
>
> The best way to do this is to plumb a context.Context through all 
> long-running functions - in particular, anything talking to the network.
> Most RPC and network frameworks provide a way to pass a Context, so 
> consistently doing this will more or less transparently cancel your business 
> logic ASAP.
> For purely CPU bound code, this is a bit more awkward, because you indeed 
> have to intersperse code like
> select {
>     case <-ctx.Done():
>         return ctx.Err()
>     default:
> }
> to make the code return early. But that should be relatively rare.

Yes.  See also https://go.dev/blog/context .

Ian

-- 
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/CAOyqgcXceQ1RxEiAasWHUgUv6w7UGHH9Sxu%2BGbbuQvU3TBWvdw%40mail.gmail.com.

Reply via email to