Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created November 26, 2010 17:33
Show Gist options
  • Save lukemorton/716989 to your computer and use it in GitHub Desktop.
Save lukemorton/716989 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
pid = fork do
def find_order
# check for order and return one if found
end
monitor = Fiber.new do
# Keep checking
loop do
# check for new orders in a loop
order = find_order
# When one is found
if order.found?
# Pass the order to handle Fiber
handle.resume order
end
# Wait 5 minutes
sleep 60*5
end
end
handle = Fiber.new do |order|
# handle it here... then resume monitoring
monitor.resume
end
end
Process.detach(pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment