Skip to content
Browse files

Added synchronize to HashCounter put/get methods

  • Loading branch information...
1 parent 2c596fa commit 18d6eb085faeb6ddfb725b2b25ffeaadfcd78a69 tbeauvais committed
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/webmock/util/hash_counter.rb
View
11 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 18d6eb0

Please sign in to comment.
Something went wrong with that request. Please try again.