Class: RubyRemoteConfig::Client
- Inherits:
-
Object
- Object
- RubyRemoteConfig::Client
- Defined in:
- lib/ruby_remote_config.rb
Instance Attribute Summary collapse
-
#cancel ⇒ Object
readonly
Returns the value of attribute cancel.
-
#refresh_interval ⇒ Object
readonly
Returns the value of attribute refresh_interval.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#initialize(repository: Repository, refresh_interval: Integer) ⇒ Client
constructor
A new instance of Client.
- #refresh ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(repository: Repository, refresh_interval: Integer) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_remote_config.rb', line 13 def initialize(repository: Repository, refresh_interval: Integer) # Create the Client instance with the provided repository and refresh interval. @repository = repository @refresh_interval = refresh_interval @cancel = Concurrent::MutexAtomicBoolean.new(false) # Refresh the configuration data for the first time to ensure the # Client is initialized with the latest data before it is used. @repository.refresh # Start the background refresh goroutine by calling the refresh function # with the newly created context and the client as arguments. Thread.new { refresh() } # Return the created Client instance, which is now ready to use. self end |
Instance Attribute Details
#cancel ⇒ Object (readonly)
Returns the value of attribute cancel.
12 13 14 |
# File 'lib/ruby_remote_config.rb', line 12 def cancel @cancel end |
#refresh_interval ⇒ Object (readonly)
Returns the value of attribute refresh_interval.
12 13 14 |
# File 'lib/ruby_remote_config.rb', line 12 def refresh_interval @refresh_interval end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
12 13 14 |
# File 'lib/ruby_remote_config.rb', line 12 def repository @repository end |
Instance Method Details
#refresh ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ruby_remote_config.rb', line 32 def refresh loop do sleep(refresh_interval) @repository.refresh() break if @cancel end end |
#stop ⇒ Object
40 41 42 |
# File 'lib/ruby_remote_config.rb', line 40 def stop @cancel.make_true end |