Module: Ione::Future::Callbacks

Included in:
Ione::Future
Defined in:
lib/ione/future.rb

Overview

Since:

  • v1.0.0

Instance Method Summary collapse

Instance Method Details

#on_failure {|error| ... } ⇒ Object

Registers a listener that will be called when this future fails. The lisener will be called with the error that failed the future as sole argument.

Yield Parameters:

  • error (Error)

    the error that failed the future

Since:

  • v1.0.0



580
581
582
583
584
585
# File 'lib/ione/future.rb', line 580

def on_failure(&listener)
  on_complete do |_, error|
    listener.call(error) if error
  end
  nil
end

#on_value {|value| ... } ⇒ Object

Registers a listener that will be called when this future becomes resolved. The listener will be called with the value of the future as sole argument.

Yield Parameters:

  • value (Object)

    the value of the resolved future

Since:

  • v1.0.0



568
569
570
571
572
573
# File 'lib/ione/future.rb', line 568

def on_value(&listener)
  on_complete do |value, error|
    listener.call(value) unless error
  end
  nil
end