Class EventMachine::TickLoop
In: lib/em/tick_loop.rb
Parent: Object

A TickLoop is useful when one needs to distribute amounts of work throughout ticks in order to maintain response times. It is also useful for simple repeated checks and metrics.

  # Here we run through an array one item per tick until it is empty,
  # printing each element.
  # When the array is empty, we return :stop from the callback, and the
  # loop will terminate.
  # When the loop terminates, the on_stop callbacks will be called.
  EM.run do
    array = (1..100).to_a

    tickloop = EM.tick_loop do
      if array.empty?
        :stop
      else
        puts array.shift
      end
    end

    tickloop.on_stop { EM.stop }
  end

Methods

new   on_stop   start   stop   stopped?  

Public Class methods

Arguments: A callback (EM::Callback) to call each tick. If the call returns +:stop+ then the loop will be stopped. Any other value is ignored.

Public Instance methods

Arguments: A callback (EM::Callback) to call once on the next stop (or immediately if already stopped).

Start the tick loop, will raise argument error if the loop is already running.

Stop the tick loop immediately, and call it‘s on_stop callbacks.

Query if the loop is stopped.

[Validate]