|| at Dec 2, 2012 at 11:46 pm
In the code you have provided there is no real difference semantically
between your two examples, except possibly the allocation of an extra
channel in the time.After() version (which may need to be garbage collected
at some point).
Both examples are very likely to introduce drift, so if that is a concern,
you would need another approach. For your situation (a repeating timer), I
suggest you use time.Tick/time.NewTicker, as it only needs to be created
once and seems to do what you need. Also, with time.Tick you can use it in
a for-range loop: http://play.golang.org/p/Ctg3_AQisl
Note: the code doesn't work on play.golang.org, since many features of the
time package are disabled for security reasons.
On Sunday, December 2, 2012 3:04:06 PM UTC-8, ryan....@gmail.com wrote:
I'm learning go and trying to figure out the preferred way to call a
Here is a gist of two ways Ive thought of how to accomplish this in go.
The first polling function uses time.Sleep inside a for loop and the other
waits to receive a message from time.After. Is there a better way to
accomplish this and are there any differences at runtime between the two
functions I created?https://gist.github.com/4191392