Class List Method List File List

# Class: Vertx::Future

Inherits:
  Object
  - Object
  - Vertx::Future
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb

## Overview

Represents the result of an action that may, or may not, have occurred yet.

## Direct Known Subclasses

CompositeFuture, VertxWeb::BridgeEvent

## Class Method Summary (collapse)

- + (::Vertx::Future) failed_future(failureMessage = nil)
  Create a failed future with the specified failure message.
- + (::Vertx::Future) future
  Create a future that hasn't completed yet.
- + (::Vertx::Future) succeeded_future(result = nil)
  Created a succeeded future with the specified result.

## Instance Method Summary (collapse)

- - (Exception) cause
  A Throwable describing failure.
- - (void) complete(result = nil)
  Set the result.
- - (true, false) complete?
  Has the future completed? It's completed if it's either succeeded or failed.
- - (Proc) completer
  @return an handler completing this future.
- - (::Vertx::Future) compose(param_1 = nil, param_2 = nil)
  Compose this future with a provided next future.
- - (void) fail(param_1 = nil)
  Set the failure.
- - (true, false) failed?
  Did it fail?.
- - (::Vertx::Future) map(param_1 = nil)
  Map the result of a future to a specific value.
- - (Object) result
  The result of the operation.
- - (self) set_handler { ... }
  Set a handler for the result.
- - (true, false) succeeded?
  Did it succeed?.

## Class Method Details

### + (`::Vertx::Future`) failed_future(failureMessage = nil)

Create a failed future with the specified failure message.

Parameters:

- failureMessage (`String`) (defaults to: `nil`) —
  the failure message

Returns:

- (`::Vertx::Future`) —
  the future

Raises:

- (`ArgumentError`)

    39
    40
    41
    42
    43
    44
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 39

    def self.failed_future(failureMessage=nil)
      if failureMessage.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:failedFuture, [Java::java.lang.String.java_class]).call(failureMessage),::Vertx::Future)
      end
      raise ArgumentError, "Invalid arguments when calling failed_future(failureMessage)"
    end

### + (`::Vertx::Future`) future

Create a future that hasn't completed yet

Returns:

- (`::Vertx::Future`) —
  the future

Raises:

- (`ArgumentError`)

    19
    20
    21
    22
    23
    24
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 19

    def self.future
      if !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:future, []).call(),::Vertx::Future)
      end
      raise ArgumentError, "Invalid arguments when calling future()"
    end

### + (`::Vertx::Future`) succeeded_future(result = nil)

Created a succeeded future with the specified result.

Parameters:

- result (`Object`) (defaults to: `nil`) —
  the result

Returns:

- (`::Vertx::Future`) —
  the future

Raises:

- (`ArgumentError`)

    28
    29
    30
    31
    32
    33
    34
    35
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 28

    def self.succeeded_future(result=nil)
      if !block_given? && result == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:succeededFuture, []).call(),::Vertx::Future)
      elsif (result.class == String  || result.class == Hash || result.class == Array || result.class == NilClass || result.class == TrueClass || result.class == FalseClass || result.class == Fixnum || result.class == Float) && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:succeededFuture, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(result)),::Vertx::Future)
      end
      raise ArgumentError, "Invalid arguments when calling succeeded_future(result)"
    end

## Instance Method Details

### - (`Exception`) cause

A Throwable describing failure. This will be null if the operation succeeded.

Returns:

- (`Exception`) —
  the cause or null if the operation succeeded.

Raises:

- (`ArgumentError`)

    103
    104
    105
    106
    107
    108
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 103

    def cause
      if !block_given?
        return ::Vertx::Util::Utils.from_throwable(@j_del.java_method(:cause, []).call())
      end
      raise ArgumentError, "Invalid arguments when calling cause()"
    end

### - (`void`) complete(result = nil)

This method returns an undefined value.

Set the result. Any handler will be called, if there is one, and the future will be marked as completed.

Parameters:

- result (`Object`) (defaults to: `nil`) —
  the result

Raises:

- (`ArgumentError`)

    71
    72
    73
    74
    75
    76
    77
    78
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 71

    def complete(result=nil)
      if !block_given? && result == nil
        return @j_del.java_method(:complete, []).call()
      elsif (result.class == String  || result.class == Hash || result.class == Array || result.class == NilClass || result.class == TrueClass || result.class == FalseClass || result.class == Fixnum || result.class == Float) && !block_given?
        return @j_del.java_method(:complete, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(result))
      end
      raise ArgumentError, "Invalid arguments when calling complete(result)"
    end

### - (`true`, `false`) complete?

Has the future completed?

It's completed if it's either succeeded or failed.

Returns:

- (`true`, `false`) —
  true if completed, false if not

Raises:

- (`ArgumentError`)

    49
    50
    51
    52
    53
    54
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 49

    def complete?
      if !block_given?
        return @j_del.java_method(:isComplete, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling complete?()"
    end

### - (`Proc`) completer

@return an handler completing this future

Returns:

- (`Proc`)

Raises:

- (`ArgumentError`)

    168
    169
    170
    171
    172
    173
    174
    175
    176
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 168

    def completer
      if !block_given?
        if @cached_completer != nil
          return @cached_completer
        end
        return @cached_completer = ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:completer, []).call()) { |val| ::Vertx::Util::Utils.to_object(val) }
      end
      raise ArgumentError, "Invalid arguments when calling completer()"
    end

### - (`::Vertx::Future`) compose(mapper) { ... } - (`::Vertx::Future`) compose(handler, composed)

Compose this future with a provided `next` future.

When this future succeeds, the `handler` will be called with the completed value, this handler should complete the next future.

If the `handler` throws an exception, the returned future will be failed with this exception.

When this future fails, the failure will be propagated to the `next` future and the `handler` will not be called.

Overloads:

- - (`::Vertx::Future`) compose(mapper) { ... }

  Yields:

  - the mapper function
- - (`::Vertx::Future`) compose(handler, composed)

  Parameters:

  - handler (`Proc`) —
    the handler
  - composed (`::Vertx::Future`) —
    the composed future

Returns:

- (`::Vertx::Future`) —
  the composed future, used for chaining

Raises:

- (`ArgumentError`)

    140
    141
    142
    143
    144
    145
    146
    147
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 140

    def compose(param_1=nil,param_2=nil)
      if block_given? && param_1 == nil && param_2 == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:compose, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_object(event)).j_del })),::Vertx::Future)
      elsif param_1.class == Proc && param_2.class.method_defined?(:j_del) && !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:compose, [Java::IoVertxCore::Handler.java_class,Java::IoVertxCore::Future.java_class]).call((Proc.new { |event| param_1.call(::Vertx::Util::Utils.from_object(event)) }),param_2.j_del),::Vertx::Future)
      end
      raise ArgumentError, "Invalid arguments when calling compose(param_1,param_2)"
    end

### - (`void`) fail(throwable) - (`void`) fail(failureMessage)

This method returns an undefined value.

Set the failure. Any handler will be called, if there is one, and the future will be marked as completed.

Overloads:

- - (`void`) fail(throwable)

  Parameters:

  - throwable (`Exception`) —
    the failure cause
- - (`void`) fail(failureMessage)

  Parameters:

  - failureMessage (`String`) —
    the failure message

Raises:

- (`ArgumentError`)

    85
    86
    87
    88
    89
    90
    91
    92
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 85

    def fail(param_1=nil)
      if param_1.is_a?(Exception) && !block_given?
        return @j_del.java_method(:fail, [Java::JavaLang::Throwable.java_class]).call(::Vertx::Util::Utils.to_throwable(param_1))
      elsif param_1.class == String && !block_given?
        return @j_del.java_method(:fail, [Java::java.lang.String.java_class]).call(param_1)
      end
      raise ArgumentError, "Invalid arguments when calling fail(param_1)"
    end

### - (`true`, `false`) failed?

Did it fail?

Returns:

- (`true`, `false`) —
  true if it failed or false otherwise

Raises:

- (`ArgumentError`)

    119
    120
    121
    122
    123
    124
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 119

    def failed?
      if !block_given?
        return @j_del.java_method(:failed, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling failed?()"
    end

### - (`::Vertx::Future`) map(mapper) { ... } - (`::Vertx::Future`) map(value)

Map the result of a future to a specific `value`.

When this future succeeds, this `value` will complete the future returned by this method call.

When this future fails, the failure will be propagated to the returned future.

Overloads:

- - (`::Vertx::Future`) map(mapper) { ... }

  Yields:

  - the mapper function
- - (`::Vertx::Future`) map(value)

  Parameters:

  - value (`Object`) —
    the value that eventually completes the mapped future

Returns:

- (`::Vertx::Future`) —
  the mapped future

Raises:

- (`ArgumentError`)

    158
    159
    160
    161
    162
    163
    164
    165
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 158

    def map(param_1=nil)
      if block_given? && param_1 == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:map, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| ::Vertx::Util::Utils.to_object(yield(::Vertx::Util::Utils.from_object(event))) })),::Vertx::Future)
      elsif (param_1.class == String  || param_1.class == Hash || param_1.class == Array || param_1.class == NilClass || param_1.class == TrueClass || param_1.class == FalseClass || param_1.class == Fixnum || param_1.class == Float) && !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:map, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(param_1)),::Vertx::Future)
      end
      raise ArgumentError, "Invalid arguments when calling map(param_1)"
    end

### - (`Object`) result

The result of the operation. This will be null if the operation failed.

Returns:

- (`Object`) —
  the result or null if the operation failed.

Raises:

- (`ArgumentError`)

    95
    96
    97
    98
    99
    100
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 95

    def result
      if !block_given?
        return ::Vertx::Util::Utils.from_object(@j_del.java_method(:result, []).call())
      end
      raise ArgumentError, "Invalid arguments when calling result()"
    end

### - (`self`) set_handler { ... }

Set a handler for the result.

If the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.

Yields:

- the Handler that will be called with the result

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    61
    62
    63
    64
    65
    66
    67
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 61

    def set_handler
      if block_given?
        @j_del.java_method(:setHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_handler()"
    end

### - (`true`, `false`) succeeded?

Did it succeed?

Returns:

- (`true`, `false`) —
  true if it succeded or false otherwise

Raises:

- (`ArgumentError`)

    111
    112
    113
    114
    115
    116
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 111

    def succeeded?
      if !block_given?
        return @j_del.java_method(:succeeded, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling succeeded?()"
    end