Class: DRbQS::TaskSource
- Inherits:
-
Object
- Object
- DRbQS::TaskSource
- Defined in:
- lib/drbqs/task_generator.rb
Instance Method Summary collapse
- #add_task(arg) ⇒ Object
- #create_add_task(*args, &block) ⇒ Object
-
#initialize(data) ⇒ TaskSource
constructor
A new instance of TaskSource.
- #wait_all_tasks ⇒ Object
Constructor Details
#initialize(data) ⇒ TaskSource
Returns a new instance of TaskSource.
6 7 8 9 10 |
# File 'lib/drbqs/task_generator.rb', line 6 def initialize(data) data.each do |key, val| instance_variable_set("@#{key.to_s}", val) end end |
Instance Method Details
#add_task(arg) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/drbqs/task_generator.rb', line 12 def add_task(arg) case arg when DRbQS::Task Fiber.yield(arg) when Array arg.each { |t| Fiber.yield(t) } else raise "Invalid type of an argument." end end |
#create_add_task(*args, &block) ⇒ Object
23 24 25 |
# File 'lib/drbqs/task_generator.rb', line 23 def create_add_task(*args, &block) add_task(DRbQS::Task.new(*args, &block)) end |
#wait_all_tasks ⇒ Object
27 28 29 |
# File 'lib/drbqs/task_generator.rb', line 27 def wait_all_tasks Fiber.yield(:wait) end |