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