Module: IOPromise::Dalli::AsyncClient

Defined in:
lib/iopromise/dalli/patch_dalli.rb

Instance Method Summary collapse

Instance Method Details

#initialize(servers = nil, options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/iopromise/dalli/patch_dalli.rb', line 9

def initialize(servers = nil, options = {})
  @async = options[:iopromise_async] == true

  super
end

#perform_async(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/iopromise/dalli/patch_dalli.rb', line 15

def perform_async(*args)
  if @async
    perform(*args)
  else
    raise ArgumentError, "Cannot perform_async when async is not enabled."
  end
rescue => ex
  # Wrap any connection errors into a promise, this is more forwards-compatible
  # if we ever attempt to make connecting/server fallback nonblocking too.
  Promise.new.tap { |p| p.reject(ex) }
end