Class: RedisRpc::SyncHandler
- Inherits:
-
Object
- Object
- RedisRpc::SyncHandler
- Defined in:
- lib/redis_rpc/response.rb
Instance Method Summary collapse
-
#initialize(secret_key, _method, timeout = 10) ⇒ SyncHandler
constructor
A new instance of SyncHandler.
- #release(res) ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(secret_key, _method, timeout = 10) ⇒ SyncHandler
Returns a new instance of SyncHandler.
42 43 44 45 46 47 48 |
# File 'lib/redis_rpc/response.rb', line 42 def initialize(secret_key, _method, timeout=10) @parser = Parser.new(secret_key) @_method = _method @timeout = timeout @lock = Mutex.new @condition = ConditionVariable.new end |
Instance Method Details
#release(res) ⇒ Object
61 62 63 64 |
# File 'lib/redis_rpc/response.rb', line 61 def release(res) @response = res @lock.synchronize { @condition.signal } end |
#sync ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/redis_rpc/response.rb', line 50 def sync @lock.synchronize { @condition.wait(@lock, @timeout) } if @response.nil? raise(Timeout::Error.new("method: #{@_method} wait for timeout #{@timeout}s")) elsif !@response[:result].nil? return @response[:result] elsif !@response[:error].nil? raise(FunctionCallbackError.new(@response[:error])) end end |