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

Create a promise that hasn't completed yet

Returns:



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

def self.promise
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Promise.java_method(:promise, []).call(),::Vertx::Promise, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling promise()"
  end
end

Instance Method Details

- (void) complete - (void) complete(result)

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.

Overloads:

  • - (void) complete(result)

    Parameters:

    • result (Object)
      the result


113
114
115
116
117
118
119
120
121
122
123
124
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 113

def complete(*args)
  if !block_given? && args[0] == nil
    return @j_del.java_method(:complete, []).call()
  elsif @j_arg_T.accept?(args[0]) && !block_given?
    return @j_del.java_method(:complete, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(args[0]))
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling complete(#{args[0]})"
  end
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


30
31
32
33
34
35
36
37
38
39
40
41
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 30

def fail(*args)
  if args[0].is_a?(Exception) && !block_given?
    return @j_del.java_method(:fail, [Java::JavaLang::Throwable.java_class]).call(::Vertx::Util::Utils.to_throwable(args[0]))
  elsif args[0].class == String && !block_given?
    return @j_del.java_method(:fail, [Java::java.lang.String.java_class]).call(args[0])
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling fail(#{args[0]})"
  end
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


44
45
46
47
48
49
50
51
52
53
54
55
56
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 44

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
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling future()"
  end
end

- (true, false) tryComplete - (true, false) tryComplete(result)

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

Overloads:

  • - (true, false) tryComplete(result)

    Parameters:

    • result (Object)
      the result

Returns:

  • (true, false)
    false when the future is already completed


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

def try_complete?(*args)
  if !block_given? && args[0] == nil
    return @j_del.java_method(:tryComplete, []).call()
  elsif @j_arg_T.accept?(args[0]) && !block_given?
    return @j_del.java_method(:tryComplete, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(args[0]))
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling try_complete?(#{args[0]})"
  end
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


94
95
96
97
98
99
100
101
102
103
104
105
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 94

def try_fail?(*args)
  if args[0].is_a?(Exception) && !block_given?
    return @j_del.java_method(:tryFail, [Java::JavaLang::Throwable.java_class]).call(::Vertx::Util::Utils.to_throwable(args[0]))
  elsif args[0].class == String && !block_given?
    return @j_del.java_method(:tryFail, [Java::java.lang.String.java_class]).call(args[0])
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling try_fail?(#{args[0]})"
  end
end