Class: Synapse::Command::FutureCallback
- Inherits:
-
CommandCallback
- Object
- CommandCallback
- Synapse::Command::FutureCallback
- Defined in:
- lib/synapse/command/command_callback.rb
Overview
Callback that provides a deferred result or exception from the execution of a command
Instance Method Summary collapse
-
#initialize ⇒ FutureCallback
constructor
A new instance of FutureCallback.
- #on_failure(exception) ⇒ undefined
- #on_success(result) ⇒ undefined
-
#result(timeout = nil) ⇒ Object
The result from the command handler.
Constructor Details
#initialize ⇒ FutureCallback
Returns a new instance of FutureCallback.
20 21 22 23 |
# File 'lib/synapse/command/command_callback.rb', line 20 def initialize @mutex = Mutex.new @condition = ConditionVariable.new end |
Instance Method Details
#on_failure(exception) ⇒ undefined
55 56 57 58 59 60 61 62 |
# File 'lib/synapse/command/command_callback.rb', line 55 def on_failure(exception) @mutex.synchronize do @dispatched = true @exception = exception @condition.broadcast end end |
#on_success(result) ⇒ undefined
44 45 46 47 48 49 50 51 |
# File 'lib/synapse/command/command_callback.rb', line 44 def on_success(result) @mutex.synchronize do @dispatched = true @result = result @condition.broadcast end end |
#result(timeout = nil) ⇒ Object
Returns The result from the command handler.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/synapse/command/command_callback.rb', line 28 def result(timeout = nil) @mutex.synchronize do unless @dispatched @condition.wait @mutex, timeout end if @exception raise @exception end @result end end |