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



585
586
587
588
589
590
# File 'lib/ione/future.rb', line 585

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



573
574
575
576
577
578
# File 'lib/ione/future.rb', line 573

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