On Thu, Oct 09, 2014 at 04:17:29AM +0200, Markus Teich wrote: > Brandon Mulcahy wrote: > > Is there a reason this wouldn't work? > > > > for { > > // ... > > time.Now().Format("Mon 02 Ý 15:04:05"), > > // ... > > time.Sleep(time.Second) > > } > > The for loop you recommended takes one second plus the time it takes to run > the remainder of the loop body, while my current implementation fires exactly > every one second.
Yes, of course there's that issue. On my machine the loop body takes ~6 ms, meaning a skip every 2-3 minutes. I think a "correct" solution would be: time.Sleep(-time.Since(time.Now().Add(time.Second).Truncate(time.Second))) Not as elegant as the Ticker channel, but it works for me. :)