Class: DelayedResult
- Inherits:
-
Object
- Object
- DelayedResult
- Defined in:
- lib/wimp.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(&resolver) ⇒ DelayedResult
constructor
A new instance of DelayedResult.
- #then(&block) ⇒ Object
- #value ⇒ Object
- #value! ⇒ Object
Constructor Details
#initialize(&resolver) ⇒ DelayedResult
Returns a new instance of DelayedResult.
4 5 6 |
# File 'lib/wimp.rb', line 4 def initialize(&resolver) @resolver = resolver end |
Class Method Details
.zip(*results, &block) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/wimp.rb', line 14 def self.zip(*results, &block) DelayedResult.new do results = results.map(&:value!) block.(*results) end end |
Instance Method Details
#then(&block) ⇒ Object
8 9 10 11 12 |
# File 'lib/wimp.rb', line 8 def then(&block) DelayedResult.new do block.(value!) end end |
#value ⇒ Object
31 32 33 |
# File 'lib/wimp.rb', line 31 def value value! end |
#value! ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/wimp.rb', line 21 def value! @value ||= @resolver.().yield_self do |val| if val&.is_a?(DelayedResult) val.value! else val end end end |