Sha256: 87754d45906318edab905bda86d18dca2bf71f95947df4ba82f10bfc6a1193b6

Contents?: true

Size: 898 Bytes

Versions: 28

Compression:

Stored size: 898 Bytes

Contents

module SplitIoClient
  module Cache
    module Adapters
      module MemoryAdapters
        # Memory adapter implementation, which stores everything inside queue
        class QueueAdapter
          def initialize(max_size)
            @max_size = max_size
            @queue = Queue.new
            @current_size = Concurrent::AtomicFixnum.new(0)
          end

          # Adds data to queue in non-blocking mode
          def add_to_queue(data)
            fail ThreadError if @current_size.value >= @max_size

            @queue.push(data)

            @current_size.increment
          end

          # Get all items from the queue
          def clear
            items = []

            loop do
              items << @queue.pop(true)

              @current_size.decrement
            end

          rescue ThreadError
            items
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
splitclient-rb-4.2.2 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.2.1 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.2.0 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.1.0 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.1.0.pre.rc2 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.1.0.pre.rc1 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.0.0 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-4.0.0.pre.rc1 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.3.0 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.3.0.pre.rc1 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.4 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.4.pre.rc5 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.4.pre.rc4 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.4.pre.rc3 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.4.pre.rc2 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.4.pre.rc1 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.3 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.3.pre.rc1 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.2 lib/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-3.2.1 lib/cache/adapters/memory_adapters/queue_adapter.rb