Method: ZMQMachine::Deferrable#callback

Defined in:
lib/zm/deferrable.rb

#callback(&block) ⇒ Object

Specify a block to be executed if and when the Deferrable object receives a status of :succeeded. See #set_deferred_status for more information.

Calling this method on a Deferrable object whose status is not yet known will cause the callback block to be stored on an internal list. If you call this method on a Deferrable whose status is :succeeded, the block will be executed immediately, receiving the parameters given to the prior #set_deferred_status call.

– If there is no status, add a callback to an internal list. If status is succeeded, execute the callback immediately. If status is failed, do nothing.



42
43
44
45
46
47
48
49
50
51
# File 'lib/zm/deferrable.rb', line 42

def callback &block
  return unless block
  @deferred_status ||= :unknown
  if @deferred_status == :succeeded
    block.call(*@deferred_args)
  elsif @deferred_status != :failed
    @callbacks ||= []
    @callbacks.unshift block
  end
end