Sha256: 599043b7e37402a2310b1f240961eca276d6432432483d506d58b4abe7179e2c

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

Contents

module Timber
  module LogDevices
    class HTTP
      # A simple thread-safe queue implementation that provides a #flush method.
      # The built-in ruby Queue class does not provide a #flush method. It also
      # implement thread waiting which is something we do not want. To keep things
      # simple and straight-forward we designed our own simple queue class.
      # @private
      class FlushableSizedQueue
        def initialize(max_size)
          @lock = Mutex.new
          @max_size = max_size
          @array = []
        end

        # Adds a message to the queue
        def enqueue(msg)
          @lock.synchronize do
            @array << msg
          end
        end

        # Flushes all message from the queue and returns them.
        def flush
          @lock.synchronize do
            old = @array
            @array = []
            return old
          end
        end

        def full?
          size >= @max_size
        end

        def size
          @array.size
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
timber-2.1.10 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.9 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.8 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.7 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.6 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.5 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.4 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.3 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.2 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.1 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0.rc6 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0.rc5 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0.rc4 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0.rc3 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0.rc2 lib/timber/log_devices/http/flushable_sized_queue.rb
timber-2.1.0.rc1 lib/timber/log_devices/http/flushable_sized_queue.rb