Class: Vertx::Promise

Inherits:
Object
  • Object
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)

Instance Method Summary (collapse)

Class Method Details

+ (::Vertx::Promise) failedPromise(cause) + (::Vertx::Promise) failedPromise(failureMessage)

Create a failed promise with the specified failureMessage.

Overloads:

  • + (::Vertx::Promise) failedPromise(cause)

    Parameters:

    • cause (Exception)
      the failure cause as a Throwable
  • + (::Vertx::Promise) failedPromise(failureMessage)

    Parameters:

    • failureMessage (String)
      the failure message

Returns:

Raises:

  • (ArgumentError)

40
41
42
43
44
45
46
47
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 40

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

+ (::Vertx::Promise) promise

Create a promise that hasn't completed yet

Returns:

Raises:

  • (ArgumentError)

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

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

+ (::Vertx::Promise) succeeded_promise(result = nil)

Created a succeeded promise with the specified result.

Parameters:

  • result (Object) (defaults to: nil)
    the result

Returns:

Raises:

  • (ArgumentError)

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

def self.succeeded_promise(result=nil)
  if !block_given? && result == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Promise.java_method(:succeededPromise, []).call(),::Vertx::Promise, nil)
  elsif ::Vertx::Util::unknown_type.accept?(result) && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Promise.java_method(:succeededPromise, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(result)),::Vertx::Promise, nil)
  end
  raise ArgumentError, "Invalid arguments when calling succeeded_promise(#{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 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)

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

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)

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

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)

110
111
112
113
114
115
116
117
118
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 110

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)

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

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)

101
102
103
104
105
106
107
108
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 101

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