Class List Method List File List

# Class: Vertx::Future

Inherits:
  Object
  - Object
  - Vertx::Future
  show all
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/future.rb

## Overview

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

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

- - (void) complete(result = nil)
  Set the result.
- - (true, false) complete?
  Has the future completed? It's completed if it's either succeeded or failed.
- - (void) fail(failureMessage = nil)
  Set the failure.
- - (void) set_handler { ... }
  Set a handler for the result.

## 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-aggregator/modules/vertx-lang-ruby/src/main/resources/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-aggregator/modules/vertx-lang-ruby/src/main/resources/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-aggregator/modules/vertx-lang-ruby/src/main/resources/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

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

    70
    71
    72
    73
    74
    75
    76
    77
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/future.rb', line 70

    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-aggregator/modules/vertx-lang-ruby/src/main/resources/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

### - (`void`) fail(failureMessage = nil)

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.

Parameters:

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

Raises:

- (`ArgumentError`)

    81
    82
    83
    84
    85
    86
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/future.rb', line 81

    def fail(failureMessage=nil)
      if failureMessage.class == String && !block_given?
        return @j_del.java_method(:fail, [Java::java.lang.String.java_class]).call(failureMessage)
      end
      raise ArgumentError, "Invalid arguments when calling fail(failureMessage)"
    end

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

This method returns an undefined value.

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

Raises:

- (`ArgumentError`)

    61
    62
    63
    64
    65
    66
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/future.rb', line 61

    def set_handler
      if block_given?
        return @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) }))
      end
      raise ArgumentError, "Invalid arguments when calling set_handler()"
    end