Class: Alexandria::ExecutionQueue
- Inherits:
-
Object
- Object
- Alexandria::ExecutionQueue
- Defined in:
- lib/alexandria/execution_queue.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#call(procedure, *args) ⇒ Object
For the requesting thread.
-
#initialize ⇒ ExecutionQueue
constructor
A new instance of ExecutionQueue.
-
#iterate ⇒ Object
For the executing thread.
- #stop ⇒ Object
- #sync_call(procedure, *args) ⇒ Object
Constructor Details
#initialize ⇒ ExecutionQueue
Returns a new instance of ExecutionQueue.
33 34 35 36 37 38 39 40 |
# File 'lib/alexandria/execution_queue.rb', line 33 def initialize @pending_calls = [] @pending_retvals = [] @protect_pending_calls = Mutex.new @protect_pending_retvals = Mutex.new @id = 0 @@current_queue = self end |
Class Method Details
.current ⇒ Object
42 43 44 45 46 |
# File 'lib/alexandria/execution_queue.rb', line 42 def self.current @@current_queue rescue nil end |
Instance Method Details
#call(procedure, *args) ⇒ Object
For the requesting thread.
49 50 51 |
# File 'lib/alexandria/execution_queue.rb', line 49 def call(procedure, *args) push(procedure, args, false) end |
#iterate ⇒ Object
For the executing thread.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/alexandria/execution_queue.rb', line 58 def iterate ary = @protect_pending_calls.synchronize do break @pending_calls.pop end return if ary.nil? id, procedure, args, need_retval = ary retval = procedure.call(*args) if need_retval @protect_pending_retvals.synchronize do @pending_retvals << [id, retval] end end end |
#stop ⇒ Object
72 73 74 |
# File 'lib/alexandria/execution_queue.rb', line 72 def stop @@current_queue = nil end |
#sync_call(procedure, *args) ⇒ Object
53 54 55 |
# File 'lib/alexandria/execution_queue.rb', line 53 def sync_call(procedure, *args) push(procedure, args, true) end |