Sha256: e14195f5a5c3405df16fdda603ac645a84d38021be26c31ac873bb684ebfb023

Contents?: true

Size: 725 Bytes

Versions: 29

Compression:

Stored size: 725 Bytes

Contents

# typed: true

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.com/terms.html

require 'sqreen/log'

module Sqreen
  # A simple size limited queue.
  # When trying to enqueue more than the capacity
  # the older elements will get thrown
  class CappedQueue < Queue
    attr_reader :capacity

    def initialize(capacity)
      @capacity = capacity
      super()
    end

    alias original_push push

    def push(value)
      until size < @capacity
        discarded = pop
        Sqreen.log.debug { "Discarded from queue: #{discarded}" }
      end
      Sqreen.log.debug { "Pushed to the queue: #{value}" }
      original_push(value)
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
sqreen-1.22.0-java lib/sqreen/capped_queue.rb
sqreen-1.22.0 lib/sqreen/capped_queue.rb
sqreen-1.21.1-java lib/sqreen/capped_queue.rb
sqreen-1.21.1 lib/sqreen/capped_queue.rb
sqreen-1.21.0-java lib/sqreen/capped_queue.rb
sqreen-1.21.0 lib/sqreen/capped_queue.rb
sqreen-1.20.4-java lib/sqreen/capped_queue.rb
sqreen-1.20.4 lib/sqreen/capped_queue.rb
sqreen-1.21.0.beta3-java lib/sqreen/capped_queue.rb
sqreen-1.21.0.beta3 lib/sqreen/capped_queue.rb
sqreen-1.20.4.beta1 lib/sqreen/capped_queue.rb
sqreen-1.19.4 lib/sqreen/capped_queue.rb
sqreen-1.20.3 lib/sqreen/capped_queue.rb
sqreen-1.20.2 lib/sqreen/capped_queue.rb
sqreen-1.21.0.beta2 lib/sqreen/capped_queue.rb
sqreen-1.21.0.beta1 lib/sqreen/capped_queue.rb
sqreen-1.20.1-java lib/sqreen/capped_queue.rb
sqreen-1.20.1 lib/sqreen/capped_queue.rb
sqreen-1.20.0-java lib/sqreen/capped_queue.rb
sqreen-1.20.0 lib/sqreen/capped_queue.rb