Sha256: d869c62cad7811ae808d052099284775f9a75e549886c9d6d8313fc17cc7b2c8

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

require 'thread'
require 'timeout'

module SplitIoClient
  module Cache
    module Stores
      class SDKBlocker
        attr_reader :splits_ready
        attr_writer :splits_thread, :segments_thread

        def initialize(config)
          @config = config

          @splits_ready = false
          @segments_ready = false
        end

        def splits_ready!
          @splits_ready = true
        end

        def segments_ready!
          @segments_ready = true
        end

        def block
          begin
            Timeout::timeout(@config.block_until_ready) do
              sleep 0.1 until ready?
              sleep 0.1 until ready?
            end
          rescue Timeout::Error
            fail SDKBlockerTimeoutExpiredException, 'SDK start up timeout expired'
          end

          @config.logger.info('SplitIO SDK is ready')
          @splits_thread.run
          @segments_thread.run
        end

        def ready?
          @splits_ready && @segments_ready
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
splitclient-rb-3.1.2 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.1 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc12 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc11 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc10 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc9 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc8 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc7 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc6 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc5 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc4 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.1.0.pre.rc2 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.0.3 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.0.3.pre.rc2 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.0.3.pre.rc1 lib/cache/stores/sdk_blocker.rb
splitclient-rb-3.0.2 lib/cache/stores/sdk_blocker.rb