class Concurrent::TVar
A `TVar` is a transactional variable - a single-element container that is used as part of a transaction - see `Concurrent::atomically`.
@!macro thread_safe_variable_comparison
{include:file:doc/tvar.md}
Public Class Methods
new(value)
click to toggle source
Create a new `TVar` with an initial value.
# File lib/concurrent/tvar.rb, line 16 def initialize(value) @value = value @version = 0 @lock = Mutex.new end
Public Instance Methods
value()
click to toggle source
Get the value of a `TVar`.
# File lib/concurrent/tvar.rb, line 23 def value Concurrent::atomically do Transaction::current.read(self) end end
value=(value)
click to toggle source
Set the value of a `TVar`.
# File lib/concurrent/tvar.rb, line 30 def value=(value) Concurrent::atomically do Transaction::current.write(self, value) end end