Class: EventMachine::TickLoop
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/em/tick_loop.rb |
Overview
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.
Class Method Summary
-
.new(*a, &b) ⇒ TickLoop
constructor
Arguments: A callback (EM::Callback) to call each tick.
Instance Attribute Summary
-
#stopped? ⇒ Boolean
readonly
Query if the loop is stopped.
Instance Method Summary
-
#on_stop(*a, &b)
Arguments: A callback (EM::Callback) to call once on the next stop (or immediately if already stopped).
-
#start
Start the tick loop, will raise argument error if the loop is already running.
-
#stop
Stop the tick loop immediately, and call it's on_stop callbacks.
- #schedule private
Constructor Details
.new(*a, &b) ⇒ TickLoop
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.
Instance Attribute Details
#stopped? ⇒ Boolean
(readonly)
Query if the loop is stopped.
# File 'lib/em/tick_loop.rb', line 60
def stopped? @stopped end
Instance Method Details
#on_stop(*a, &b)
Arguments: A callback (EM::Callback) to call once on the next stop (or immediately if already stopped).
#schedule (private)
[ GitHub ]#start
Start the tick loop, will raise argument error if the loop is already running.
# File 'lib/em/tick_loop.rb', line 66
def start raise ArgumentError, "double start" unless @stopped @stopped = false schedule end
#stop
Stop the tick loop immediately, and call it's on_stop callbacks.
# File 'lib/em/tick_loop.rb', line 52
def stop @stopped = true until @stops.empty? @stops.shift.call end end