Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created December 8, 2010 21:38
Show Gist options
  • Save phiggins/733961 to your computer and use it in GitHub Desktop.
Save phiggins/733961 to your computer and use it in GitHub Desktop.
require 'eventmachine'
require 'benchmark'
x = 0
t = Benchmark.realtime do
EM.run do
EM.add_timer(1.5) { raise "OMG" }
time = EM.current_time + 0.002
EM.add_periodic_timer(0) do
if EM.current_time >= time
x += 1
time += 0.002
EM.stop if x == 512
end
end
end
end
puts t
puts x
# $ ruby em_ghetto_realtime.rb
# 1.0243961811065674
# 512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment