Skip to content

Commit

Permalink
Use concurrent Array and Hash
Browse files Browse the repository at this point in the history
To avoid concurrency issue with urn next method
  • Loading branch information
fumimowdan committed Oct 19, 2023
1 parent cbecf29 commit 910c77a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ gem "phonelib"
###############

gem "audited", "~> 5.4"
gem "concurrent-ruby", require: "concurrent"
gem "concurrent-ruby-ext"
gem "config", "~> 4.2"
gem "devise", "~> 4.9"
gem "flipper"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ GEM
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.2.2)
concurrent-ruby-ext (1.2.2)
concurrent-ruby (= 1.2.2)
config (4.2.1)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
Expand Down Expand Up @@ -476,6 +478,8 @@ DEPENDENCIES
brakeman
bundler-audit
capybara
concurrent-ruby
concurrent-ruby-ext
config (~> 4.2)
dartsass-rails (~> 0.5.0)
debug
Expand Down
4 changes: 2 additions & 2 deletions app/models/urn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def next(route)
private

def routes
@routes ||= Hash.new do |hash, route|
@routes ||= Concurrent::Hash.new do |hash, route|
hash[route] = urn_enumerator(
config.codes.fetch(route),
config.seeds.fetch(route, Random.new_seed),
Expand All @@ -102,7 +102,7 @@ def available_urns(code, seed, used_urns)
end

def urn_enumerator(code, seed, used_urns)
list = available_urns(code, seed, used_urns)
list = Concurrent::Array.new(available_urns(code, seed, used_urns))
error_msg = "you have exhausted urn for code #{code} you need to increase the size of the suffix"

Enumerator.new do |yielder|
Expand Down

0 comments on commit 910c77a

Please sign in to comment.