Class: FiberQueue
- Inherits:
-
Object
- Object
- FiberQueue
- Defined in:
- lib/rubee/async/fiber_queue.rb
Instance Method Summary collapse
- #add(task, args = {}) ⇒ Object
- #done? ⇒ Boolean
- #fan_out! ⇒ Object
-
#initialize ⇒ FiberQueue
constructor
A new instance of FiberQueue.
Constructor Details
#initialize ⇒ FiberQueue
Returns a new instance of FiberQueue.
2 3 4 |
# File 'lib/rubee/async/fiber_queue.rb', line 2 def initialize @fibers = [] end |
Instance Method Details
#add(task, args = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/rubee/async/fiber_queue.rb', line 6 def add(task, args = {}) fiber = Fiber.new do task.new.perform(**args) rescue => e puts "Fiber Error: #{e.}" end @fibers << fiber end |
#done? ⇒ Boolean
23 24 25 |
# File 'lib/rubee/async/fiber_queue.rb', line 23 def done? @fibers.none?(&:alive?) end |
#fan_out! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rubee/async/fiber_queue.rb', line 15 def fan_out! while @fibers.any?(&:alive?) @fibers.each do |fiber| fiber.resume if fiber.alive? end end end |