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



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

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
109
110
# File 'lib/concurrent/futures.rb', line 100

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