Class: Concurrent::Futures::Ref

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

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Ref

Returns a new instance of Ref.



126
127
128
129
# File 'lib/concurrent/futures.rb', line 126

def initialize( value=nil )
  @lock = Mutex.new
  @value = value
end

Instance Method Details

#exchange(value) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/concurrent/futures.rb', line 131

def exchange( value )
  @lock.synchronize do
    result = @value
    @value = value
    result
  end
end

#modify(&block) ⇒ Object



139
140
141
142
143
144
# File 'lib/concurrent/futures.rb', line 139

def modify( &block )
  @lock.synchronize do
    value = @value
    @value = Future.async { block.call value }
  end
end