Both use the runtime timers underneath. Ticker requires an extra channel send.
Tracking this down was interesting! On Thu, 27 Sep 2018, 14:56 David Wahlstedt, <david.wahlstedt....@gmail.com> wrote: > I mean that an ordinary go thread executing a sleep instruction may risk > to be starved by the scheduler, so the real sleeping time is likely to be > longer. But with the ticker, a incoming message in the channel waking up a > routine that waits for it, things may behave differently? > > /David > > > Den onsdag 26 september 2018 kl. 17:33:29 UTC+2 skrev Sebastien Binet: >> >> >> >> On Wed, Sep 26, 2018 at 2:29 PM David Wahlstedt <david.wah...@gmail.com> >> wrote: >> >>> Thanks--nice! >>> Will this be less reliable than the built-in Ticker (that uses >>> runtimeTimer), besides the intentional randomness? >>> >> >> modulo the possible bug(s) I may have unintentionally introduced, I think >> it should be as reliable. >> (perhaps a bit less efficient than runtimeTimer, I haven't had the >> intellectual curiosity to look at what runtimeTimer does.) >> >> -s >> >> >>> >>> /David >>> >>> Den tisdag 25 september 2018 kl. 18:43:33 UTC+2 skrev Sebastien Binet: >>>> >>>> >>>> >>>> On Tue, Sep 25, 2018 at 11:34 AM David Wahlstedt < >>>> david.wah...@gmail.com> wrote: >>>> >>>>> Hi, >>>>> What would be a nice way to implement a ticker that generates events >>>>> according to a Poisson process? >>>>> The built-in Ticker in ticker.go uses a runtimeTimer that has a field >>>>> called period. >>>>> I would like to implement a "random ticker" such that each tick >>>>> interval is random, using ExpFloat64() * d, with average duration d, >>>>> instead of a fixed interval. >>>>> I could have a go routine that sleeps a random amount of time in a >>>>> loop, but it would be nice to use something similar to the ticker. >>>>> >>>> >>>> just for fun: https://play.golang.org/p/kt0qVQ41E1C >>>> (yes, it uses a goroutine that sleeps a random amount of time in a >>>> loop.) >>>> >>>> -s >>>> >>> -- >>> 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...@googlegroups.com. >> >> >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > 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. > -- 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.