Skip to content

Commit 9df399e

Browse files
committed
Eager load the constants
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
1 parent b7c5f6d commit 9df399e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/global_id.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
require 'global_id/global_id'
2+
require 'active_support'
23

34
autoload :SignedGlobalID, 'global_id/signed_global_id'
45

56
class GlobalID
6-
autoload :Locator, 'global_id/locator'
7-
autoload :Identification, 'global_id/identification'
8-
autoload :Verifier, 'global_id/verifier'
7+
extend ActiveSupport::Autoload
8+
9+
eager_autoload do
10+
autoload :Locator, 'global_id/locator'
11+
autoload :Identification, 'global_id/identification'
12+
autoload :Verifier, 'global_id/verifier'
13+
end
914
end

0 commit comments

Comments
 (0)