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:



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

def self.failed_future(*args)
  if args[0].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(args[0])),::Vertx::Future, nil)
  elsif args[0].class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:failedFuture, [Java::java.lang.String.java_class]).call(args[0]),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling failed_future(#{args[0]})"
  end
end

+ (::Vertx::Future) future(handler) { ... }

Create a future that hasn't completed yet and that is passed to the handler before it is returned.

Yields:

  • the handler

Returns:



271
272
273
274
275
276
277
278
279
280
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 271

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

+ (::Vertx::Future) succeededFuture + (::Vertx::Future) succeededFuture(result)

Created a succeeded future with the specified result.

Overloads:

  • + (::Vertx::Future) succeededFuture(result)

    Parameters:

    • result (Object)
      the result

Returns:



298
299
300
301
302
303
304
305
306
307
308
309
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 298

def self.succeeded_future(*args)
  if !block_given? && args[0] == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:succeededFuture, []).call(),::Vertx::Future, nil)
  elsif ::Vertx::Util::unknown_type.accept?(args[0]) && !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(args[0])),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling succeeded_future(#{args[0]})"
  end
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.


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

def cause
  if !block_given?
    return ::Vertx::Util::Utils.from_throwable(@j_del.java_method(:cause, []).call())
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling cause()"
  end
end

- (true, false) isComplete

Has the future completed?

It's completed if it's either succeeded or failed.

Returns:

  • (true, false)
    true if completed, false if not


366
367
368
369
370
371
372
373
374
375
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 366

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

- (::Vertx::Future) compose(mapper) { ... } - (::Vertx::Future) compose(successMapper, failureMapper) { ... }

Compose this future with a successMapper and failureMapper functions.

When this future (the one on which compose is called) succeeds, the successMapper 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.

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

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

Overloads:

  • - (::Vertx::Future) compose(mapper) { ... }

    Yields:

    • the mapper function
  • - (::Vertx::Future) compose(successMapper, failureMapper) { ... }

    Parameters:

    • successMapper (Proc)
      the function mapping the success

    Yields:

    • the function mapping the failure

Returns:



255
256
257
258
259
260
261
262
263
264
265
266
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 255

def compose(*args)
  if block_given? && args[0] == nil && args[1] == 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)
  elsif args[0].class == Proc && block_given? && args[1] == nil
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:compose, [Java::JavaUtilFunction::Function.java_class,Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| args[0].call(@j_arg_T.wrap(event)).j_del unless args[0] == nil }),(Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)).j_del unless !block_given? })),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling compose(#{args[0]},#{args[1]})"
  end
end

- (::Vertx::Context) context

Returns the context associated with this future or null when

Returns:



283
284
285
286
287
288
289
290
291
292
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 283

def context
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:context, []).call(),::Vertx::Context)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling context()"
  end
end

- (true, false) failed

Did it fail?

Returns:

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


152
153
154
155
156
157
158
159
160
161
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 152

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

- (::Vertx::Future) flatMap(mapper) { ... }

Alias for #compose.

Yields:

Returns:



215
216
217
218
219
220
221
222
223
224
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 215

def flat_map(*args)
  if block_given? && args[0] == nil
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:flatMap, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(@j_arg_T.wrap(event)).j_del unless !block_given? })),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling flat_map(#{args[0]})"
  end
end

- (Proc) getHandler

Returns the handler for the result

Returns:

  • (Proc)
    the handler for the result


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

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



320
321
322
323
324
325
326
327
328
329
330
331
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 320

def map(*args)
  if block_given? && args[0] == 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?(args[0]) && !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(args[0])),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling map(#{args[0]})"
  end
end

- (::Vertx::Future) mapEmpty

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:



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

def map_empty
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:mapEmpty, []).call(),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling map_empty()"
  end
end

- (self) onComplete(handler) { ... }

Add a handler to be notified of the result.

Yields:

  • the handler that will be called with the result

Returns:

  • (self)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 84

def on_complete
  if true
    if (block_given?)
      @j_del.java_method(:onComplete, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? @j_arg_T.wrap(ar.result) : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:onComplete, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? @j_arg_T.wrap(ar.result) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling on_complete()"
  end
end

- (self) onFailure(handler) { ... }

Add a handler to be notified of the failed result.

Yields:

  • the handler that will be called with the failed result

Returns:

  • (self)


119
120
121
122
123
124
125
126
127
128
129
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 119

def on_failure
  if true
    @j_del.java_method(:onFailure, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling on_failure()"
  end
end

- (self) onSuccess(handler) { ... }

Add a handler to be notified of the succeeded result.

Yields:

  • the handler that will be called with the succeeded result

Returns:

  • (self)


350
351
352
353
354
355
356
357
358
359
360
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 350

def on_success
  if true
    @j_del.java_method(:onSuccess, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(@j_arg_T.wrap(event)) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling on_success()"
  end
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:



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

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

- (::Vertx::Future) otherwiseEmpty

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:



183
184
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 183

def otherwise_empty
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:otherwiseEmpty, []).call(),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling otherwise_empty()"
  end
end

- (::Vertx::Future) recover(mapper) { ... }

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:



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

def recover(*args)
  if block_given? && args[0] == 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
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling recover(#{args[0]})"
  end
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.


228
229
230
231
232
233
234
235
236
237
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 228

def result
  if !block_given?
    return @j_arg_T.wrap(@j_del.java_method(:result, []).call())
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling result()"
  end
end

- (self) setHandler(handler) { ... }

Like #on_complete.

Yields:

Returns:

  • (self)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 47

def set_handler
  if true
    if (block_given?)
      @j_del.java_method(:setHandler, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? @j_arg_T.wrap(ar.result) : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:setHandler, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? @j_arg_T.wrap(ar.result) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling set_handler()"
  end
end

- (true, false) succeeded

Did it succeed?

Returns:

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


335
336
337
338
339
340
341
342
343
344
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/future.rb', line 335

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