On Wed, Jan 12, 2022 at 5:02 AM Tobias Klausmann <klaus...@schwarzvogel.de>
wrote


> So what is the *idiomatic* way of being able to use `continue` (or
> something like it), yet have "always do this" code at the end of the
> loop? As I understand it, `defer` only works for ends of functions, not
> ends of blocks, and label breaks only work for breaks, obviously.
>

I generally pull the bulk of the loop body into another function/method
(usually called tick()) that I call inside the loop just before sleeping.
 (or more typically, a select{} block checking a ticker and a context)

(I like Rob's option, too. -- although that doesn't work with select{}
blocks as well)

-- 
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/CANrC0Bi4k%2BURHVmOsiZkMTp9UR1EGSDO0hvgij20zv1dsrP%2BFg%40mail.gmail.com.

Reply via email to