Class: ProcessQueue
- Inherits:
-
PartyProxy
- Object
- PartyProxy
- ProcessQueue
- Defined in:
- lib/threadparty/partyproxies/processqueue.rb
Instance Method Summary collapse
- #execute(queue_override = nil) ⇒ Object
-
#initialize ⇒ ProcessQueue
constructor
A new instance of ProcessQueue.
Methods inherited from PartyProxy
dsl_accessor, dsl_method, is_proxy, #threaded
Constructor Details
#initialize ⇒ ProcessQueue
Returns a new instance of ProcessQueue.
9 10 11 12 |
# File 'lib/threadparty/partyproxies/processqueue.rb', line 9 def initialize super @modify_queue = false end |
Instance Method Details
#execute(queue_override = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/threadparty/partyproxies/processqueue.rb', line 14 def execute(queue_override = nil) raise ArgumentError, 'I don\'t have a perform' unless @perform process_queue = Queue.new() result_queue = Queue.new() #Oldstuff gets pushed in first [queue_override, @queue].each do |possible_things| case possible_things when Queue possible_things.to_a! else possible_things.to_a end.each do |thing| process_queue.push(thing) end end threaded do |number| while item = process_queue.pop(true) case @perform.arity when 0 result_queue << @perform.call() when 1 result_queue << @perform.call( @modify_queue ? process_queue : item ) else result_queue << @perform.call( @modify_queue ? process_queue : item, *item ) end end end result_queue.to_a! end |