Class: Lowdown::Client::RequestGroup::Callbacks

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/lowdown/client/request_group.rb

Instance Method Summary collapse

Constructor Details

#initialize(condition) ⇒ Callbacks

Returns a new instance of Callbacks.



42
43
44
45
# File 'lib/lowdown/client/request_group.rb', line 42

def initialize(condition)
  @callbacks = {}
  @condition = condition
end

Instance Method Details

#add(notification_id, callback) ⇒ Object

Raises:

  • (ArgumentError)


51
52
53
54
# File 'lib/lowdown/client/request_group.rb', line 51

def add(notification_id, callback)
  raise ArgumentError, "A notification ID is required." unless notification_id
  @callbacks[notification_id] = callback
end

#empty?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/lowdown/client/request_group.rb', line 47

def empty?
  @callbacks.empty?
end

#handle_apns_response(response, context:) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/lowdown/client/request_group.rb', line 56

def handle_apns_response(response, context:)
  callback = @callbacks.delete(response.id)
  if callback.is_a?(Proc)
    callback.call(response, context)
  else
    callback.send(:handle_apns_response, response, context: context)
  end
ensure
  @condition.signal if @callbacks.empty?
end