Class: Vertx::Future

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb

Overview

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

Direct Known Subclasses

CompositeFuture, VertxWeb::BridgeEvent

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)


43
44
45
46
47
48
49
50
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 43

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

Returns:

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 20

def self.future
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Future.java_method(:future, []).call(),::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)


29
30
31
32
33
34
35
36
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 29

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)


109
110
111
112
113
114
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 109

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

- (void) complete(result = nil)

This method returns an undefined value.

Set the result. Any handler will be called, if there is one, and the future will be marked as completed.

Parameters:

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

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 77

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

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


55
56
57
58
59
60
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 55

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

- (Proc) completer

Returns an handler completing this future

Returns:

  • (Proc)
    an handler completing this future

Raises:

  • (ArgumentError)


173
174
175
176
177
178
179
180
181
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 173

def completer
  if !block_given?
    if @cached_completer != nil
      return @cached_completer
    end
    return @cached_completer = ::Vertx::Util::Utils.to_async_result_handler_proc(@j_del.java_method(:completer, []).call()) { |val| @j_arg_T.unwrap(val) }
  end
  raise ArgumentError, "Invalid arguments when calling completer()"
end

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

Compose this future with a provided next future.

When this (the one on which compose is called) future succeeds, the handler will be called with the completed value, this handler should complete the next future.

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

When this future fails, the failure will be propagated to the next future and the handler will not be called.

Overloads:

Returns:

Raises:

  • (ArgumentError)


146
147
148
149
150
151
152
153
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 146

def compose(param_1=nil,param_2=nil)
  if block_given? && param_1 == nil && param_2 == 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 })),::Vertx::Future, nil)
  elsif param_1.class == Proc && param_2.class.method_defined?(:j_del) && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:compose, [Java::IoVertxCore::Handler.java_class,Java::IoVertxCore::Future.java_class]).call((Proc.new { |event| param_1.call(@j_arg_T.wrap(event)) }),param_2.j_del),::Vertx::Future, nil)
  end
  raise ArgumentError, "Invalid arguments when calling compose(#{param_1},#{param_2})"
end

- (void) fail(throwable) - (void) fail(failureMessage)

This method returns an undefined value.

Set the failure. Any handler will be called, if there is one, and the future will be marked as completed.

Overloads:

  • - (void) fail(throwable)

    Parameters:

    • throwable (Exception)
      the failure cause
  • - (void) fail(failureMessage)

    Parameters:

    • failureMessage (String)
      the failure message

Raises:

  • (ArgumentError)


91
92
93
94
95
96
97
98
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 91

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

- (true, false) failed?

Did it fail?

Returns:

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

Raises:

  • (ArgumentError)


125
126
127
128
129
130
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 125

def failed?
  if !block_given?
    return @j_del.java_method(:failed, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling failed?()"
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)


164
165
166
167
168
169
170
171
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 164

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))) })),::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

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


101
102
103
104
105
106
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 101

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)


67
68
69
70
71
72
73
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 67

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


117
118
119
120
121
122
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/future.rb', line 117

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