Skip to content

Instantly share code, notes, and snippets.

@neektza
Created April 14, 2017 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neektza/45bac5e0e09254578f1bb89b1c04bf37 to your computer and use it in GitHub Desktop.
Save neektza/45bac5e0e09254578f1bb89b1c04bf37 to your computer and use it in GitHub Desktop.
module EventMachine
def self.run_deferred_callbacks
until (@resultqueue ||= []).empty?
result,cback = @resultqueue.pop
cback.call result if cback
end
size = @next_tick_mutex.synchronize { @next_tick_queue.size }
size.times do |i|
callback = @next_tick_mutex.synchronize { @next_tick_queue.shift }
begin
callback.call
ensure
EM.next_tick {} if $!
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment