Class: Concurrent::Futures::Lazy
- Inherits:
-
Object
- Object
- Concurrent::Futures::Lazy
- Defined in:
- lib/concurrent/futures.rb
Instance Method Summary collapse
-
#initialize(&block) ⇒ Lazy
constructor
A new instance of Lazy.
- #inspect ⇒ Object
- #value ⇒ Object
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
#inspect ⇒ Object
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 |
#value ⇒ Object
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 |