Class: Whenner::Callback
- Inherits:
-
Object
- Object
- Whenner::Callback
- Defined in:
- lib/whenner/callback.rb
Overview
A Callback is used internally by Deferred to store its callbacks.
It provides the same call
interface as regular blocks, but this
will always return a promise for the block's return value.
When the block in question returns a regular object, a new deferred for that object is created and immediately fulfilled. When the block raises an exception, the returned promise is rejected with that exception. When the block returns a promise itself, the returned deferred will mimic that promise -- as if that promise is what actually was returned.
Instance Attribute Summary collapse
-
#block ⇒ #call
readonly
A callable object, usually a Ruby block.
-
#deferred ⇒ Deferred
readonly
The deferred object representing the block's return value.
Instance Method Summary collapse
-
#call(*args) ⇒ Promise
Run the block, passing it any given arguments, and return a promise for its return value.
-
#initialize(block) ⇒ Callback
constructor
A new instance of Callback.
-
#promise ⇒ Promise
For this callback's #deferred.
Constructor Details
Instance Attribute Details
#block ⇒ #call (readonly)
A callable object, usually a Ruby block.
15 16 17 |
# File 'lib/whenner/callback.rb', line 15 def block @block end |
#deferred ⇒ Deferred (readonly)
Returns the deferred object representing the block's return value.
19 20 21 |
# File 'lib/whenner/callback.rb', line 19 def deferred @deferred end |
Instance Method Details
#call(*args) ⇒ Promise
Run the block, passing it any given arguments, and return a promise for its return value.
30 31 32 33 |
# File 'lib/whenner/callback.rb', line 30 def call(*args) update_deferred(*args) deferred.promise end |