Class: Wire::MessageCallback
- Inherits:
-
Object
- Object
- Wire::MessageCallback
- Defined in:
- lib/wire.rb
Instance Method Summary collapse
-
#initialize(message_hash, message_id, callback, timeout_seconds) ⇒ MessageCallback
constructor
A new instance of MessageCallback.
- #set_result(result) ⇒ Object
Constructor Details
#initialize(message_hash, message_id, callback, timeout_seconds) ⇒ MessageCallback
Returns a new instance of MessageCallback.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/wire.rb', line 57 def initialize (, , callback, timeout_seconds) @semaphore = Mutex.new @callback = callback @result = nil Thread.new do sleep(timeout_seconds) .delete() @semaphore.synchronize do if @result.nil? callback.timeout end end end end |
Instance Method Details
#set_result(result) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/wire.rb', line 73 def set_result (result) @semaphore.synchronize do @result = result @callback.complete(@result) end end |