Go makes it easy to use intermediates, and the code will be easier to read 
for someone else, possibly years from now.

{
  intervalMS := *Int64Flag_xxxxxxxxxxxxxxIntervalMS
  interval := time.Duration(intervalMS) * time.Millisecond
  elapsed := time.Now().Sub(timeStart)
  time.Sleep( interval - elapsed)
}

or, if you want to do this in several places:

sleepRemainder := func( timeStart time, intervalMS int ) {
  interval := time.Duration(intervalMS) * time.Millisecond
  elapsed := time.Now().Sub(timeStart)
  time.Sleep( interval - elapsed )
}

sleepRemainder( timeStart, Int64Flag_xxxxxxxxxxxxxxIntervalMS )

I've done this even when the code is only used once.  Sometimes it makes 
the code clearer by making the overall structure clearer.

Jonathan

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to