Created
October 3, 2011 22:34
-
-
Save russ/1260445 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
class Queue | |
@@jobs = [] | |
def self.enqueue(klass, *arguments) | |
@@jobs << { :class => klass, :arguments => arguments } | |
end | |
def self.work | |
while job = @@jobs.shift | |
puts job[:class].perform(*job[:arguments]) | |
end | |
end | |
end | |
class MyJob | |
def self.perform(numbers) | |
numbers.reduce(:+) | |
end | |
end | |
Queue.enqueue(MyJob, [ 1, 2, 3, 4, 5 ]) | |
Queue.enqueue(MyJob, [ 6, 7, 8, 9, 10 ]) | |
Queue.work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment