Class List Method List File List

# Class: Vertx::Promise

Inherits:
  Object
  - Object
  - Vertx::Promise
  show all
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb

## Overview

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

The #future method returns the Future associated with a promise, the future can be used for getting notified of the promise completion and retrieve its value.

A promise extends `Handler>` so it can be used as a callback.

## Direct Known Subclasses

VertxBridgeCommon::BaseBridgeEvent

## Class Method Summary (collapse)

- + (::Vertx::Promise) promise
  Create a promise that hasn't completed yet.

## Instance Method Summary (collapse)

- - (void) complete(result = nil)
  Set the result.
- - (void) fail(param_1 = nil)
  Calls #fail with the message.
- - (::Vertx::Future) future
  The Future associated with this promise, it can be used to be aware of the promise completion.
- - (true, false) try_complete?(result = nil)
  Like #complete but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.
- - (true, false) try_fail?(param_1 = nil)
  Calls #fail with the message.

## Class Method Details

### + (`::Vertx::Promise`) promise

Create a promise that hasn't completed yet

Returns:

- (`::Vertx::Promise`) —
  the promise

Raises:

- (`ArgumentError`)

    25
    26
    27
    28
    29
    30
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 25

    def self.promise
      if !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Promise.java_method(:promise, []).call(),::Vertx::Promise, nil)
      end
      raise ArgumentError, "Invalid arguments when calling promise()"
    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 promise will be marked as completed.

Any handler set on the associated promise will be called.

Parameters:

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

Raises:

- (`ArgumentError`)

    36
    37
    38
    39
    40
    41
    42
    43
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 36

    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

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

This method returns an undefined value.

Calls #fail with the `message`.

Overloads:

- - (`void`) fail(cause)

  Parameters:

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

  Parameters:

  - message (`String`) —
    the failure message

Raises:

- (`ArgumentError`)

    50
    51
    52
    53
    54
    55
    56
    57
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 50

    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

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

Returns the Future associated with this promise, it can be used to be aware of the promise completion

Returns:

- (`::Vertx::Future`) —
  the Future associated with this promise, it can be used to be aware of the promise completion

Raises:

- (`ArgumentError`)

    85
    86
    87
    88
    89
    90
    91
    92
    93
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 85

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

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

Like #complete but returns `false` when the promise is already completed instead of throwing an IllegalStateException, it returns `true` otherwise.

Parameters:

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

Returns:

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

Raises:

- (`ArgumentError`)

    62
    63
    64
    65
    66
    67
    68
    69
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 62

    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(message)

Calls #fail with the `message`.

Overloads:

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

  Parameters:

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

  Parameters:

  - message (`String`) —
    the failure message

Returns:

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

Raises:

- (`ArgumentError`)

    76
    77
    78
    79
    80
    81
    82
    83
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 76

    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