kameleoon-client-ruby 3.20.0 → 3.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6e939e54b9b0f43a46d27b3ce7d1d442916d036a7db9ca5159645ffc869415b
4
- data.tar.gz: 98b6e2c2b04c183ba5052379066e3eff95c9ffdc2b28963a0bd106dcf8adb0db
3
+ metadata.gz: ea79d87e992d2f5bf9829c8082427c18251101be90f50c769b46242a1f4fc272
4
+ data.tar.gz: 305d07e5adee2b86cf58acc2b01f8a47f4161daeb06efbc8239e7a585ec355cd
5
5
  SHA512:
6
- metadata.gz: c4eb181ded7a566731df5e6af6bcb271fcf852c27503b5e0c44be51eb93b729decb88c378732f9a9584d5d1ef452e71a5ba651a39d20a06f7e689a3b016bc65a
7
- data.tar.gz: 997194371128c0c25cd394ab7ed22e05a0b57684915c96268874ab9e426aa3e0228f396488e77da61c2b122798eeccfee2ad1e8785900ddff24452faac953025
6
+ metadata.gz: c3319b271cf4053f01e9fab40b0133cd609a800f55fd3de84f19b76209d2fcbe5438672aa24a42dc39c1dd4dade97641956c2cff1f5c5c0cee8ece0d80636ca8
7
+ data.tar.gz: 10dfdd35cf97d0adb20ed4a866c4b6739be6ec11458c267a550bf02f6e5ae2542b282b2c30ac33ae94797e3e4a8ce8dd6187406ef1d85603c2d02d0b9f09d44f
@@ -3,37 +3,47 @@
3
3
  require 'concurrent'
4
4
 
5
5
  module Kameleoon
6
+ # ClientReadiness is a cross-thread latch signalling that the SDK has
7
+ # successfully loaded its configuration.
8
+ #
9
+ # It is created on the thread that builds the client but released (`set`) from
10
+ # the background thread(s) performing configuration fetches, so it relies on
11
+ # Concurrent::Event (which allows cross-thread release) rather than a
12
+ # read/write lock (whose write lock must be released by the acquiring thread).
13
+ #
14
+ # A failed fetch does NOT release the latch: the client keeps retrying in the
15
+ # background and the latch is released as soon as any fetch succeeds. Callers
16
+ # should bound their `wait` with a timeout so they are never blocked forever
17
+ # when the configuration can never be loaded.
6
18
  class ClientReadiness
7
- attr_reader :is_initializing, :success
8
-
9
19
  def initialize
10
- @is_initializing = false
11
20
  @success = false
12
- @condition = Concurrent::ReadWriteLock.new
13
- reset
21
+ @event = Concurrent::Event.new
14
22
  end
15
23
 
16
- def reset
17
- @success = false
18
- unless @is_initializing
19
- @is_initializing = true
20
- @condition.acquire_write_lock
21
- end
24
+ # @return [Boolean] whether the SDK has become ready (configuration loaded).
25
+ def success
26
+ @success
22
27
  end
23
28
 
29
+ # Record a fetch outcome. A successful fetch marks the client ready and
30
+ # unblocks all waiting threads; a failed fetch is ignored so that a later
31
+ # successful retry can still release the latch. Idempotent and safe to call
32
+ # from any thread.
24
33
  def set(success)
25
- @success = success
26
- if @is_initializing
27
- @condition.release_write_lock
28
- @is_initializing = false
29
- end
34
+ return unless success
35
+
36
+ @success = true
37
+ @event.set
30
38
  end
31
39
 
32
- def wait
33
- if @is_initializing
34
- @condition.acquire_read_lock
35
- @condition.release_read_lock
36
- end
40
+ # Block until the SDK becomes ready or the timeout elapses.
41
+ #
42
+ # @param timeout [Numeric, nil] maximum number of seconds to wait;
43
+ # nil waits indefinitely.
44
+ # @return [Boolean] whether the SDK is ready.
45
+ def wait(timeout = nil)
46
+ @event.wait(timeout)
37
47
  @success
38
48
  end
39
49
  end
@@ -92,9 +92,24 @@ module Kameleoon
92
92
  site_code, config)
93
93
  end
94
94
 
95
- def wait_init
96
- Logging::KameleoonLogger.info('CALL: KameleoonClient.wait_init')
97
- result = @readiness.wait
95
+ ##
96
+ # Block until the SDK has loaded its configuration and is ready to use.
97
+ #
98
+ # If the initial fetch fails the client keeps retrying in the background, so
99
+ # this method returns as soon as any fetch succeeds. The wait is always
100
+ # bounded by a timeout, so it never blocks indefinitely: when the timeout
101
+ # elapses before the configuration is loaded, the method returns false.
102
+ #
103
+ # @param [Integer, nil] timeout_millisecond Maximum time to wait, in
104
+ # milliseconds. When nil or negative, config.default_timeout_millisecond
105
+ # is applied.
106
+ # @return [Boolean] true if the SDK is ready, false if the timeout elapsed first.
107
+ def wait_init(timeout_millisecond = nil)
108
+ Logging::KameleoonLogger.info('CALL: KameleoonClient.wait_init(timeout_millisecond: %s)', timeout_millisecond)
109
+ if timeout_millisecond.nil? || timeout_millisecond.negative?
110
+ timeout_millisecond = @config.default_timeout_millisecond
111
+ end
112
+ result = @readiness.wait(timeout_millisecond / 1000.0)
98
113
  Logging::KameleoonLogger.info('RETURN: KameleoonClient.wait_init -> (result: %s)', result)
99
114
  result
100
115
  end
@@ -822,7 +837,8 @@ module Kameleoon
822
837
  Logging::KameleoonLogger.error('Initial configuration fetch failed: %s', e)
823
838
  end
824
839
  @readiness.set(ok)
825
- manage_configuration_update(@data_manager.data_file.settings.real_time_update) if ok
840
+ real_time_update = ok && @data_manager.data_file.settings.real_time_update
841
+ manage_configuration_update(real_time_update)
826
842
  end
827
843
  end
828
844
 
@@ -834,6 +850,9 @@ module Kameleoon
834
850
  rescue StandardError => e
835
851
  Logging::KameleoonLogger.error('Error occurred during configuration fetching: %s', e)
836
852
  end
853
+ # Release any threads still waiting in `wait_init` once a (re)fetch
854
+ # finally succeeds after an unsuccessful initial fetch.
855
+ @readiness.set(ok)
837
856
  real_time_update = @data_manager.data_file.settings.real_time_update
838
857
  if !ok && real_time_update
839
858
  @data_manager.data_file.settings.real_time_update = false
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kameleoon
4
- SDK_VERSION = '3.20.0'
4
+ SDK_VERSION = '3.21.0'
5
5
  SDK_NAME = 'RUBY'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kameleoon-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.20.0
4
+ version: 3.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-05 00:00:00.000000000 Z
11
+ date: 2026-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request