Created
November 26, 2010 17:33
-
-
Save lukemorton/716989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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