Class: RedisRpc::SyncHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_rpc/response.rb

Instance Method Summary collapse

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

#syncObject



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