Class: Concurrent::Futures::Lazy

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Lazy

Returns a new instance of Lazy.



96
97
98
# File 'lib/concurrent/futures.rb', line 96

def initialize( &block )
  @lock = Mutex.new
end

Instance Method Details

#inspectObject



110
111
112
113
114
115
116
117
118
# File 'lib/concurrent/futures.rb', line 110

def inspect
  @lock.synchronize do
    if @block
      "#<Lazy pending #{ @block.inspect }>"
    else
      "#<Lazy requested #{ @value.inspect }>"
    end
  end
end

#valueObject



100
101
102
103
104
105
106
107
108
# File 'lib/concurrent/futures.rb', line 100

def value
  @lock.synchronize do
    if @block
      @value = Thunk.new Thread.new( &block )
      @block = nil
    end
    @value
  end
end