lib/asynchronic/data_store/in_memory.rb in asynchronic-4.0.1 vs lib/asynchronic/data_store/in_memory.rb in asynchronic-4.0.2
- old
+ new
@@ -13,11 +13,11 @@
end
def initialize
@hash = {}
@mutex = Mutex.new
- @keys_mutex = Hash.new { |h,k| h[k] = Mutex.new }
+ @keys_mutex = {}
self.class.connections[object_id] = self
end
def [](key)
Marshal.load(hash[key.to_s]) if hash.key? key.to_s
@@ -39,9 +39,12 @@
def keys
hash.keys.map { |k| Key[k] }
end
def synchronize(key, &block)
+ mutex.synchronize do
+ keys_mutex[key] ||= Mutex.new
+ end
keys_mutex[key].synchronize(&block)
end
def connection_args
[object_id]
\ No newline at end of file