Class: MrDarcy::Promise::ChildPromise
- Inherits:
-
Object
- Object
- MrDarcy::Promise::ChildPromise
- Defined in:
- lib/mr_darcy/promise/child_promise.rb
Overview
A special variety of promise created by Base#then and Base#fail methods.
Instance Attribute Summary collapse
-
#promise ⇒ Object
Returns the value of attribute promise.
-
#reject_block ⇒ Object
Returns the value of attribute reject_block.
-
#resolve_block ⇒ Object
Returns the value of attribute resolve_block.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ ChildPromise
constructor
A new instance of ChildPromise.
-
#parent_rejected(value) ⇒ Object
Called by the parent promise when it rejects.
-
#parent_resolved(value) ⇒ Object
Called by the parent promise when it resolves.
Constructor Details
#initialize(opts = {}) ⇒ ChildPromise
Returns a new instance of ChildPromise.
9 10 11 |
# File 'lib/mr_darcy/promise/child_promise.rb', line 9 def initialize opts={} self.promise = MrDarcy.promise(opts) {} end |
Instance Attribute Details
#promise ⇒ Object
Returns the value of attribute promise.
7 8 9 |
# File 'lib/mr_darcy/promise/child_promise.rb', line 7 def promise @promise end |
#reject_block ⇒ Object
Returns the value of attribute reject_block.
7 8 9 |
# File 'lib/mr_darcy/promise/child_promise.rb', line 7 def reject_block @reject_block end |
#resolve_block ⇒ Object
Returns the value of attribute resolve_block.
7 8 9 |
# File 'lib/mr_darcy/promise/child_promise.rb', line 7 def resolve_block @resolve_block end |
Instance Method Details
#parent_rejected(value) ⇒ Object
Called by the parent promise when it rejects.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mr_darcy/promise/child_promise.rb', line 27 def parent_rejected value begin return reject_with value unless handles_reject? new_value = result_for :reject, value return defer_resolution_via new_value if thenable? new_value resolve_with new_value rescue Exception => e handle_exception e end end |
#parent_resolved(value) ⇒ Object
Called by the parent promise when it resolves.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mr_darcy/promise/child_promise.rb', line 14 def parent_resolved value begin return resolve_with value unless handles_resolve? new_value = result_for :resolve, value return defer_resolution_via new_value if thenable? new_value resolve_with new_value rescue Exception => e handle_exception e end end |