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.



128
129
130
131
# File 'lib/concurrent/futures.rb', line 128

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

Instance Method Details

#exchange(value) ⇒ Object



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

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

#modify(&block) ⇒ Object



141
142
143
144
145
146
# File 'lib/concurrent/futures.rb', line 141

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