Sha256: f85242cfc78834a7f6423efb22d555cb8187742365b4d236b9c6eb2b0f4a41ac

Contents?: true

Size: 411 Bytes

Versions: 10

Compression:

Stored size: 411 Bytes

Contents

module Kraps
  class TimeoutQueue
    include MonitorMixin

    def initialize
      super

      @cond = new_cond
      @queue = []
    end

    def enq(item)
      synchronize do
        @queue << item
        @cond.signal
      end
    end

    def deq(timeout:)
      synchronize do
        @cond.wait(timeout) if @queue.empty?

        return @queue.empty? ? nil : @queue.shift
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kraps-0.10.0 lib/kraps/timeout_queue.rb
kraps-0.9.0 lib/kraps/timeout_queue.rb
kraps-0.8.0 lib/kraps/timeout_queue.rb
kraps-0.7.0 lib/kraps/timeout_queue.rb
kraps-0.6.0 lib/kraps/timeout_queue.rb
kraps-0.5.0 lib/kraps/timeout_queue.rb
kraps-0.4.0 lib/kraps/timeout_queue.rb
kraps-0.3.0 lib/kraps/timeout_queue.rb
kraps-0.2.0 lib/kraps/timeout_queue.rb
kraps-0.1.0 lib/kraps/timeout_queue.rb