Class: Qwirk::Adapter::InMemory::ReplyQueue
- Inherits:
-
Object
- Object
- Qwirk::Adapter::InMemory::ReplyQueue
- Defined in:
- lib/qwirk/adapter/in_memory/reply_queue.rb
Instance Method Summary collapse
-
#initialize(name) ⇒ ReplyQueue
constructor
A new instance of ReplyQueue.
- #timeout_read(timeout) ⇒ Object
- #to_s ⇒ Object
- #write(obj) ⇒ Object
Constructor Details
#initialize(name) ⇒ ReplyQueue
Returns a new instance of ReplyQueue.
6 7 8 9 10 11 |
# File 'lib/qwirk/adapter/in_memory/reply_queue.rb', line 6 def initialize(name) @name = name @outstanding_hash_mutex = Mutex.new @read_condition = ConditionVariable.new @array = [] end |
Instance Method Details
#timeout_read(timeout) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/qwirk/adapter/in_memory/reply_queue.rb', line 13 def timeout_read(timeout) @outstanding_hash_mutex.synchronize do return @array.shift unless @array.empty? return nil unless timeout > 0 timed_read_condition_wait(timeout) return @array.shift end return nil end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/qwirk/adapter/in_memory/reply_queue.rb', line 31 def to_s "reply_queue:#{@name}" end |
#write(obj) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/qwirk/adapter/in_memory/reply_queue.rb', line 23 def write(obj) @outstanding_hash_mutex.synchronize do @array << obj @read_condition.signal return end end |