Skip to content

Commit

Permalink
Merge pull request #244 from tbeauvais/synchronize_hash_counter
Browse files Browse the repository at this point in the history
HashCounter put/get methods should be synchronized
  • Loading branch information
bblimke committed Feb 17, 2013
2 parents e1712df + 18d6eb0 commit a672d97
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/webmock/util/hash_counter.rb
Expand Up @@ -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)
Expand Down

0 comments on commit a672d97

Please sign in to comment.