Question

there is a method EventMachine.next_tick (http://eventmachine.rubyforge.org/EventMachine.html#next_tick-class_method). How big is the tick interval? How to control it? Can the tick interval be set?

Was it helpful?

Solution

Eventmachine Ticks basically match with each run of the reactor event loop. Using next_tick will run the block on the next available run of the reactor loop. Wether this means the next actual run, or more likely, at some point in the near future is based on if there are other events that are waiting to be picked up by the reactor loop. For instance, any blocks of code that where queue using add_timer or add_periodic_timer are run first, then other events like incoming network traffic is processed.

A "tick" in Eventmachine isn't really a measurement of time, it's a counter of the number of times the reactor loop executes. If you have blocking operations in your reactor loop, then each tick will take longer to process.

If you need to know approximately when your should be run, then use add_timer or add_periodic_timer instead ofnext_tick`. But as theres no guarantee that the reactor loop be available at the exact moment the timer should fire, it's almost impossible to use Eventmachine for accurate timer intervals.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top