Class: DpStmMap::InMemoryStmMap
- Inherits:
-
Object
- Object
- DpStmMap::InMemoryStmMap
- Defined in:
- lib/dp_stm_map/InMemoryStmMap.rb
Instance Method Summary collapse
- #atomic(timeout = nil) ⇒ Object
- #atomic_read ⇒ Object
-
#initialize ⇒ InMemoryStmMap
constructor
A new instance of InMemoryStmMap.
- #on_atomic(&block) ⇒ Object
- #validate_atomic(&block) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryStmMap
Returns a new instance of InMemoryStmMap.
96 97 98 99 100 101 |
# File 'lib/dp_stm_map/InMemoryStmMap.rb', line 96 def initialize @mutex=Mutex.new @state={} @validators=[] @listeners=[] end |
Instance Method Details
#atomic(timeout = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dp_stm_map/InMemoryStmMap.rb', line 114 def atomic timeout=nil @mutex.synchronize do view=AtomicView.new @state result=yield view changes=view.changes @validators.each do |validator| validator.call changes end view.commit @listeners.each do |listener| begin listener.call changes rescue end end result end end |
#atomic_read ⇒ Object
138 139 140 141 142 |
# File 'lib/dp_stm_map/InMemoryStmMap.rb', line 138 def atomic_read @mutex.synchronize do yield AtomicReadView.new @state end end |
#on_atomic(&block) ⇒ Object
104 105 106 |
# File 'lib/dp_stm_map/InMemoryStmMap.rb', line 104 def on_atomic &block @listeners << block end |
#validate_atomic(&block) ⇒ Object
109 110 111 |
# File 'lib/dp_stm_map/InMemoryStmMap.rb', line 109 def validate_atomic &block @validators << block end |