Skip to content

Commit

Permalink
Merge pull request #80 from mensfeld/patch-1
Browse files Browse the repository at this point in the history
Make registry fully thread safe
  • Loading branch information
flash-gordon authored Nov 23, 2022
2 parents 079c1f9 + 97dda9a commit 9247042
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/rom/factory/sequences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ def self.[](relation)

# @api private
def initialize
@mutex = Mutex.new
reset
end

# @api private
def next(key)
registry[key] += 1
@mutex.synchronize do
registry[key] += 1
end
end

# @api private
def reset
@registry = Concurrent::Map.new { |h, k| h[k] = 0 }
@registry = Concurrent::Map.new { |h, k| h.compute_if_absent(k) { 0 } }
self
end
end
Expand Down

0 comments on commit 9247042

Please sign in to comment.