Sha256: c223ceec9cc53c97e986cd6fa276d9a2ef693a0b91340bce433fecf138b17750

Contents?: true

Size: 950 Bytes

Versions: 19

Compression:

Stored size: 950 Bytes

Contents

module SplitIoClient
  module Cache
    module Adapters
      module MemoryAdapters
        # Memory adapter implementation, which stores everything inside sized queue
        class SizedQueueAdapter
          def initialize(size)
            @size = size
            @queue = SizedQueue.new(queue_size)
          end

          # Adds data to queue in non-blocking mode
          def add_to_queue(data)
            # IMPORTANT: this requires Ruby >= 2.2, consider changing implementation
            @queue.push(data, true)
          end

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

            loop { items << @queue.pop(true) }
          rescue ThreadError
            # Last queue item reached
            items
          end

          private

          # Return 1 to prevent an exception
          def queue_size
            @size <= 0 ? 1 : @size
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
splitclient-rb-3.2.4.pre.rc2 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.2.4.pre.rc1 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.2.3 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.2.3.pre.rc1 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.2.2 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.2.1 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.2.0 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.3 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.3.pre.rc3 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.3.pre.rc2 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.3.pre.rc1 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.2 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.1 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.0 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.0.pre.rc12 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.0.pre.rc11 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.0.pre.rc10 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.0.pre.rc9 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb
splitclient-rb-3.1.0.pre.rc8 lib/cache/adapters/memory_adapters/sized_queue_adapter.rb