Class: Libuv::Q::Promise Abstract
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#trace ⇒ Object
Allows a backtrace to be included in any errors.
Instance Method Summary collapse
-
#catch(&blk) ⇒ Promise
regardless of when the promise was or will be resolved / rejected, calls the error callback asynchronously if the promise is rejected.
-
#finally ⇒ Promise
allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value.
- #progress(&blk) ⇒ Object
-
#ruby_catch ⇒ Object
This allows subclasses to make use of the catch feature.
-
#value ⇒ Object
A future that provides the value or raises an error if a rejection occurs.
Instance Attribute Details
#trace ⇒ Object
Allows a backtrace to be included in any errors
14 15 16 |
# File 'lib/libuv/q.rb', line 14 def trace @trace end |
Instance Method Details
#catch(&blk) ⇒ Promise
regardless of when the promise was or will be resolved / rejected, calls the error callback asynchronously if the promise is rejected.
22 23 24 |
# File 'lib/libuv/q.rb', line 22 def catch(&blk) self.then(nil, blk) end |
#finally ⇒ Promise
allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful to release resources or do some clean-up that needs to be done whether the promise was rejected or resolved.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/libuv/q.rb', line 43 def finally handleCallback = lambda { |value, isResolved| callbackOutput = nil begin callbackOutput = yield rescue Exception => e @reactor.log e, 'performing promise finally callback', @trace return make_promise(e, false, @reactor) end if callbackOutput.is_a?(Promise) return callbackOutput.then(proc { make_promise(value, isResolved, @reactor) }, proc { |err| make_promise(err, false, @reactor) }) else return make_promise(value, isResolved, @reactor) end } self.then(proc {|val| handleCallback.call(val, true) }, proc{|err| handleCallback.call(err, false) }) end |
#progress(&blk) ⇒ Object
27 28 29 |
# File 'lib/libuv/q.rb', line 27 def progress(&blk) self.then(nil, nil, blk) end |
#ruby_catch ⇒ Object
This allows subclasses to make use of the catch feature
11 |
# File 'lib/libuv/q.rb', line 11 alias_method :ruby_catch, :catch |