Skip to content

Commit

Permalink
Eager load the constants
Browse files Browse the repository at this point in the history
In a thread-based backend like Sidekiq, there is a possibility that
autoload may occur simultaneously in multiple threads, and as a result,
it is presumed that an error may be caused by contention of autoload.

In order to avoid the above issue, eager load the constants on boot.
Maybe fixes #101
  • Loading branch information
y-yagi committed Aug 14, 2017
1 parent b7c5f6d commit 9df399e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/global_id.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
require 'global_id/global_id'
require 'active_support'

autoload :SignedGlobalID, 'global_id/signed_global_id'

class GlobalID
autoload :Locator, 'global_id/locator'
autoload :Identification, 'global_id/identification'
autoload :Verifier, 'global_id/verifier'
extend ActiveSupport::Autoload

eager_autoload do
autoload :Locator, 'global_id/locator'
autoload :Identification, 'global_id/identification'
autoload :Verifier, 'global_id/verifier'
end
end

0 comments on commit 9df399e

Please sign in to comment.