module AWS::Core::AsyncHandle

def __send_signal(kind)

def __send_signal(kind)
  @_async_status = kind
  @_async_callbacks.map do |cb|
    cb[kind]
  end.compact.each {|block| block.call } if @_async_callbacks
end

def on_complete(&block)

call the callback immediately.
If this is called when the task has already completed, it will

end
puts "It #{status == :success ? 'did' : 'did not'} work!"
handle.on_complete do |status|

regardless of its status. Yields the status to the block.
Registers a callback to be called when the task is complete,
def on_complete(&block)
  if !@_async_status.nil?
    block.call(@_async_status)
  else
    (@_async_callbacks ||= []) << {
      :failure => lambda { block.call(:failure) },
      :success => lambda { block.call(:success) }
    }
  end
end

def on_failure(&block)

call the callback immediately.
If this is called when the task has already failed, it will

handle.on_failure { puts "It didn't work!" }

Registers a callback to be called when the task fails.
def on_failure(&block)
  if @_async_status == :failure
    block.call
  else
    (@_async_callbacks ||= []) << { :failure => block }
  end
end

def on_success(&block)

successfully, it will call the callback immediately.
If this is called when the task has already completed

handle.on_success { puts "It worked!" }

the task.
Registers a callback to be called on successful completion of
def on_success(&block)
  if @_async_status == :success
    block.call
  else
    (@_async_callbacks ||= []) << { :success => block }
  end
end

def signal_failure

Called to signal failure and fire off the failure and complete callbacks.
def signal_failure
  __send_signal(:failure)
end

def signal_success

Called to signal success and fire off the success and complete callbacks.
def signal_success
  __send_signal(:success)
end