Class: DelayedResult

Inherits:
Object
  • Object
show all
Defined in:
lib/wimp.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#valueObject



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