Sha256: 91007abc2dbc741beaa25fd8041d57dfd17a051f8a91ef9eaa9d2833abe9c30f

Contents?: true

Size: 439 Bytes

Versions: 1

Compression:

Stored size: 439 Bytes

Contents

require "thread"

module Tennis::Backend
  class RabbitQueue
    def initialize
      @mutex = Mutex.new
      @queue = []
      @received = ConditionVariable.new
    end

    def <<(x)
      @mutex.synchronize do
        @queue << x
        @received.signal
      end
    end

    def pop(timeout = nil)
      @mutex.synchronize do
        @received.wait(@mutex, timeout) if @queue.empty?
        @queue.shift
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tennis-jobs-rmq-0.4.0 lib/tennis/backend/rabbit/queue.rb