Permalink
Browse files

Merge pull request #244 from tbeauvais/synchronize_hash_counter

HashCounter put/get methods should be synchronized
  • Loading branch information...
2 parents e1712df + 18d6eb0 commit a672d9789b02cfe3e769f2a6f1cea20f72da68f6 @bblimke committed Feb 17, 2013
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/webmock/util/hash_counter.rb
@@ -6,13 +6,18 @@ def initialize
self.hash = {}
@order = {}
@max = 0
+ @lock = Mutex.new
end
def put key, num=1
- hash[key] = (hash[key] || 0) + num
- @order[key] = @max = @max + 1
+ @lock.synchronize do
+ hash[key] = (hash[key] || 0) + num
+ @order[key] = @max = @max + 1
+ end
end
def get key
- hash[key] || 0
+ @lock.synchronize do
+ hash[key] || 0
+ end
end
def each(&block)

0 comments on commit a672d97

Please sign in to comment.