lib/asynchronic/data_store/in_memory.rb in asynchronic-1.2.0 vs lib/asynchronic/data_store/in_memory.rb in asynchronic-1.2.1
- old
+ new
@@ -5,10 +5,11 @@
include Helper
def initialize(hash={})
@hash = {}
@mutex = Mutex.new
+ @keys_mutex = Hash.new { |h,k| h[k] = Mutex.new }
self.class.connections[object_id] = self
end
def [](key)
@hash[key.to_s]
@@ -22,9 +23,13 @@
@hash.delete key.to_s
end
def keys
@hash.keys.map { |k| Key.new k }
+ end
+
+ def synchronize(key, &block)
+ @keys_mutex[key].synchronize &block
end
def connection_args
[object_id]
end
\ No newline at end of file