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(param_1 = nil)
  Create a failed future with the specified failure message.
- + (::Vertx::Future) future { ... }
  Create a future that hasn't completed yet and that is passed to the handler before it is returned.
- + (::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
  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)
  Try to 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.
- - (::Vertx::Future) map_empty
  Map the result of a future to null.
- - (::Vertx::Future) otherwise(param_1 = nil)
  Map the failure of a future to a specific value.
- - (::Vertx::Future) otherwise_empty
  Map the failure of a future to null.
- - (::Vertx::Future) recover(mapper = nil) { ... }
  Handles a failure of this Future by returning the result of another Future.
- - (Object) result
  The result of the operation.
- - (self) set_handler { ... }
  Set a handler for the result.
- - (true, false) succeeded
  Did it succeed?.
- - (true, false) try_complete(result = nil)
  Set the failure.
- - (true, false) try_fail(param_1 = nil)
  Try to set the failure.

## Class Method Details

### + (`::Vertx::Future`) failedFuture(t) + (`::Vertx::Future`) failedFuture(failureMessage)

Create a failed future with the specified failure message.

Overloads:

- + (`::Vertx::Future`) failedFuture(t)

  Parameters:

  - t (`Exception`) —
    the failure cause as a Throwable
- + (`::Vertx::Future`) failedFuture(failureMessage)

  Parameters:

  - failureMessage (`String`) —
    the failure message

Returns:

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

Raises:

- (`ArgumentError`)

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

    def self.failed_future(param_1=nil)
      if param_1.is_a?(Exception) && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:failedFuture, [Java::JavaLang::Throwable.java_class]).call(::Vertx::Util::Utils.to_throwable(param_1)),::Vertx::Future, nil)
      elsif param_1.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:failedFuture, [Java::java.lang.String.java_class]).call(param_1),::Vertx::Future, nil)
      end
      raise ArgumentError, "Invalid arguments when calling failed_future(#{param_1})"
    end

### + (`::Vertx::Future`) future { ... }

Create a future that hasn't completed yet and that is passed to the `handler` before it is returned.

Yields:

- the handler

Returns:

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

Raises:

- (`ArgumentError`)

    21
    22
    23
    24
    25
    26
    27
    28
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 21

    def self.future
      if !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:future, []).call(),::Vertx::Future, nil)
      elsif block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:future, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Future, nil)) })),::Vertx::Future, nil)
      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`)

    32
    33
    34
    35
    36
    37
    38
    39
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 32

    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, nil)
      elsif ::Vertx::Util::unknown_type.accept?(result) && !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, nil)
      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`)

    137
    138
    139
    140
    141
    142
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 137

    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`)

    80
    81
    82
    83
    84
    85
    86
    87
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 80

    def complete(result=nil)
      if !block_given? && result == nil
        return @j_del.java_method(:complete, []).call()
      elsif @j_arg_T.accept?(result) && !block_given?
        return @j_del.java_method(:complete, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(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`)

    58
    59
    60
    61
    62
    63
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 58

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

### - (`Proc`) completer

Returns an handler completing this future

Returns:

- (`Proc`) —
  an handler completing this future

Raises:

- (`ArgumentError`)

    215
    216
    217
    218
    219
    220
    221
    222
    223
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 215

    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| @j_arg_T.unwrap(val) }
      end
      raise ArgumentError, "Invalid arguments when calling completer()"
    end

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

Compose this future with a provided `next` future.

When this (the one on which `compose` is called) 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)

  Parameters:

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

Returns:

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

Raises:

- (`ArgumentError`)

    174
    175
    176
    177
    178
    179
    180
    181
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 174

    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(@j_arg_T.wrap(event)).j_del })),::Vertx::Future, nil)
      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(@j_arg_T.wrap(event)) }),param_2.j_del),::Vertx::Future, nil)
      end
      raise ArgumentError, "Invalid arguments when calling compose(#{param_1},#{param_2})"
    end

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

This method returns an undefined value.

Try to set the failure. When it happens, any handler will be called, if there is one, and the future will be marked as completed.

Overloads:

- - (`void`) fail(cause)

  Parameters:

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

  Parameters:

  - failureMessage (`String`) —
    the failure message

Raises:

- (`ArgumentError`)

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

    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`)

    153
    154
    155
    156
    157
    158
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 153

    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`)

    192
    193
    194
    195
    196
    197
    198
    199
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 192

    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(@j_arg_T.wrap(event))) })),::Vertx::Future, nil)
      elsif ::Vertx::Util::unknown_type.accept?(param_1) && !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, nil)
      end
      raise ArgumentError, "Invalid arguments when calling map(#{param_1})"
    end

### - (`::Vertx::Future`) map_empty

Map the result of a future to `null`.

This is a conveniency for `future.map((T) null)` or `future.map((Void) null)`.

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

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

Returns:

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

Raises:

- (`ArgumentError`)

    208
    209
    210
    211
    212
    213
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 208

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

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

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

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

When this future succeeds, the result will be propagated to the returned future.

Overloads:

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

  Yields:

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

  Parameters:

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

Returns:

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

Raises:

- (`ArgumentError`)

    244
    245
    246
    247
    248
    249
    250
    251
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 244

    def otherwise(param_1=nil)
      if block_given? && param_1 == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:otherwise, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| @j_arg_T.unwrap(yield(::Vertx::Util::Utils.from_throwable(event))) })),::Vertx::Future, nil)
      elsif @j_arg_T.accept?(param_1) && !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:otherwise, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(param_1)),::Vertx::Future, nil)
      end
      raise ArgumentError, "Invalid arguments when calling otherwise(#{param_1})"
    end

### - (`::Vertx::Future`) otherwise_empty

Map the failure of a future to `null`.

This is a convenience for `future.otherwise((T) null)`.

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

When this future succeeds, the result will be propagated to the returned future.

Returns:

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

Raises:

- (`ArgumentError`)

    260
    261
    262
    263
    264
    265
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 260

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

### - (`::Vertx::Future`) recover(mapper = nil) { ... }

Handles a failure of this Future by returning the result of another Future. If the mapper fails, then the returned future will be failed with this failure.

Yields:

- A function which takes the exception of a failure and returns a new future.

Returns:

- (`::Vertx::Future`) —
  A recovered future

Raises:

- (`ArgumentError`)

    228
    229
    230
    231
    232
    233
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 228

    def recover(mapper=nil)
      if block_given? && mapper == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:recover, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)).j_del })),::Vertx::Future, nil)
      end
      raise ArgumentError, "Invalid arguments when calling recover(#{mapper})"
    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`)

    129
    130
    131
    132
    133
    134
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 129

    def result
      if !block_given?
        return @j_arg_T.wrap(@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`)

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

    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 ? @j_arg_T.wrap(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`)

    145
    146
    147
    148
    149
    150
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 145

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

### - (`true`, `false`) try_complete(result = nil)

Set the failure. 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

Returns:

- (`true`, `false`) —
  false when the future is already completed

Raises:

- (`ArgumentError`)

    105
    106
    107
    108
    109
    110
    111
    112
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 105

    def try_complete(result=nil)
      if !block_given? && result == nil
        return @j_del.java_method(:tryComplete, []).call()
      elsif @j_arg_T.accept?(result) && !block_given?
        return @j_del.java_method(:tryComplete, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(result))
      end
      raise ArgumentError, "Invalid arguments when calling try_complete(#{result})"
    end

### - (`true`, `false`) tryFail(cause) - (`true`, `false`) tryFail(failureMessage)

Try to set the failure. When it happens, any handler will be called, if there is one, and the future will be marked as completed.

Overloads:

- - (`true`, `false`) tryFail(cause)

  Parameters:

  - cause (`Exception`) —
    the failure cause
- - (`true`, `false`) tryFail(failureMessage)

  Parameters:

  - failureMessage (`String`) —
    the failure message

Returns:

- (`true`, `false`) —
  false when the future is already completed

Raises:

- (`ArgumentError`)

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

    def try_fail(param_1=nil)
      if param_1.is_a?(Exception) && !block_given?
        return @j_del.java_method(:tryFail, [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(:tryFail, [Java::java.lang.String.java_class]).call(param_1)
      end
      raise ArgumentError, "Invalid arguments when calling try_fail(#{param_1})"
    end