Skip to content

Instantly share code, notes, and snippets.

@neektza
Created April 14, 2017 17:58
Show Gist options
  • Save neektza/ae22ab111d59f327aea99a1fad6ec0da to your computer and use it in GitHub Desktop.
Save neektza/ae22ab111d59f327aea99a1fad6ec0da to your computer and use it in GitHub Desktop.
module EventMachine
class Reactor
def run_timers
@timers.each do |t|
if t.first <= @current_loop_time
@timers.delete t
EventMachine::event_callback "", TimerFired, t.last
else
break
end
end
end
def run_heartbeats
if @next_heartbeat <= @current_loop_time
@next_heartbeat = @current_loop_time + HeartbeatInterval
@selectables.each {|k,io| io.heartbeat}
end
end
def crank_selectables
readers = @selectables.values.select {|io| io.select_for_reading?}
writers = @selectables.values.select {|io| io.select_for_writing?}
s = select( readers, writers, nil, @timer_quantum)
s and s[1] and s[1].each {|w| w.eventable_write }
s and s[0] and s[0].each {|r| r.eventable_read }
@selectables.delete_if do |k,io|
if io.close_scheduled?
io.close
true
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment