Class: Vertx::Future

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

Overview

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

Direct Known Subclasses

CompositeFuture, HttpClientRequest

Class Method Summary (collapse)

Instance Method Summary (collapse)

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:

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 45

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:

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 22

def self.future
  if true
    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::Promise, nil)) unless !block_given? })),::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:

Raises:

  • (ArgumentError)


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

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)


93
94
95
96
97
98
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 93

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

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


57
58
59
60
61
62
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 57

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

- (::Vertx::Future) compose(mapper = nil) { ... }

Compose this future with a mapper function.

When this future (the one on which compose is called) succeeds, the mapper will be called with the completed value and this mapper returns another future object. This returned future completion will complete the future returned by this method call.

If the mapper throws an exception, the returned future will be failed with this exception.

When this future fails, the failure will be propagated to the returned future and the mapper will not be called.

Yields:

  • the mapper function

Returns:

Raises:

  • (ArgumentError)


127
128
129
130
131
132
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 127

def compose(mapper=nil)
  if block_given? && mapper == 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 unless !block_given? })),::Vertx::Future, nil)
  end
  raise ArgumentError, "Invalid arguments when calling compose(#{mapper})"
end

- (true, false) failed?

Did it fail?

Returns:

  • (true, false)
    true if it failed or false otherwise

Raises:

  • (ArgumentError)


109
110
111
112
113
114
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 109

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

- (Proc) get_handler

Returns the handler for the result

Returns:

  • (Proc)
    the handler for the result

Raises:

  • (ArgumentError)


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

def get_handler
  if !block_given?
    return ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:getHandler, []).call()) { |val| @j_arg_T.unwrap(val) }
  end
  raise ArgumentError, "Invalid arguments when calling get_handler()"
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:

Raises:

  • (ArgumentError)


143
144
145
146
147
148
149
150
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 143

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))) unless !block_given? })),::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:

Raises:

  • (ArgumentError)


159
160
161
162
163
164
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 159

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:

Raises:

  • (ArgumentError)


185
186
187
188
189
190
191
192
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 185

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))) unless !block_given? })),::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:

Raises:

  • (ArgumentError)


201
202
203
204
205
206
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 201

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:

Raises:

  • (ArgumentError)


169
170
171
172
173
174
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 169

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 unless !block_given? })),::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)


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

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)


69
70
71
72
73
74
75
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 69

def set_handler
  if true
    @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) } unless !block_given?))
    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)


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

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