Class: Vertx::Promise
- Inherits:
-
Object
- Object
- Vertx::Promise
- 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
Class Method Summary (collapse)
-
+ (::Vertx::Promise) failed_promise(*args)
Create a failed promise with the specified failureMessage.
-
+ (::Vertx::Promise) promise
Create a promise that hasn't completed yet.
-
+ (::Vertx::Promise) succeeded_promise(*args)
Created a succeeded promise with the specified result.
Instance Method Summary (collapse)
-
- (void) complete(*args)
Set the result.
-
- (void) fail(*args)
Calls #fail with the message.
-
- (::Vertx::Future) future
The Future associated with this promise, it can be used to be aware of the promise completion.
-
- (true, false) try_complete?(*args)
Like #complete but returns false when the promise is already completed instead of throwing an IllegalStateException, it returns true otherwise.
-
- (true, false) try_fail?(*args)
Calls #fail with the message.
Class Method Details
+ (::Vertx::Promise) failedPromise(cause) + (::Vertx::Promise) failedPromise(failureMessage)
Create a failed promise with the specified
failureMessage
.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 48 def self.failed_promise(*args) if args[0].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(args[0])),::Vertx::Promise, nil) elsif args[0].class == String && !block_given? return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Promise.java_method(:failedPromise, [Java::java.lang.String.java_class]).call(args[0]),::Vertx::Promise, nil) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling failed_promise(#{args[0]})" end end |
+ (::Vertx::Promise) promise
Create a promise that hasn't completed yet
113 114 115 116 117 118 119 120 121 122 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 113 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 |
+ (::Vertx::Promise) succeededPromise + (::Vertx::Promise) succeededPromise(result)
Created a succeeded promise with the specified
result
.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 65 def self.succeeded_promise(*args) if !block_given? && args[0] == nil return ::Vertx::Util::Utils.safe_create(Java::IoVertxCore::Promise.java_method(:succeededPromise, []).call(),::Vertx::Promise, nil) elsif ::Vertx::Util::unknown_type.accept?(args[0]) && !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(args[0])),::Vertx::Promise, nil) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling succeeded_promise(#{args[0]})" 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.
148 149 150 151 152 153 154 155 156 157 158 159 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 148 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)
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
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 79 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.
98 99 100 101 102 103 104 105 106 107 108 109 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 98 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
.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/promise.rb', line 129 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 |