Skip to content

Instantly share code, notes, and snippets.

@vincenting
Created January 8, 2014 06:52
Show Gist options
  • Select an option

  • Save vincenting/8312820 to your computer and use it in GitHub Desktop.

Select an option

Save vincenting/8312820 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'fiber'
def set_interval(millisec, &block)
Fiber.new do
end_time = Time.now.to_i + millisec
loop do
if Time.now.to_i > end_time
end_time = Time.now.to_i + millisec
block.call if block_given?
else
sleep 0.02
chomp = Fiber.yield
case chomp
when Fixnum
end_time += chomp - millisec
millisec = chomp
when 'Quit'
break
end
end
end
end
end
def clear_interval(interval_obj)
interval_obj.resume 'Quit'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment