class DpStmMap::InMemoryStmMap

Public Class Methods

new() click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 96
def initialize
  @mutex=Mutex.new
  @state={}
  @validators=[]
  @listeners=[]
end

Public Instance Methods

atomic(timeout=nil) { |view| ... } click to toggle source
# 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() { |atomic_read_view state| ... } click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 138
def atomic_read
  @mutex.synchronize do
    yield AtomicReadView.new @state
  end
end
on_atomic(&block) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 104
def on_atomic &block
  @listeners << block
end
validate_atomic(&block) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 109
def validate_atomic &block
  @validators << block
end