Sha256: 7f751736d9d51ab5570bd2fb57fb5a395a3e0c284425cef2846984379a9eb4b2

Contents?: true

Size: 508 Bytes

Versions: 1

Compression:

Stored size: 508 Bytes

Contents

class Localjob
  class Channel
    attr_accessor :queues

    def initialize(queues)
      @queues = [queues].flatten.map { |q| queue_from_name(q) }
    end

    def <<(queue)
      @queues << queue_from_name(queue)
    end

    def shift
      begin
        (queue,), = IO.select(@queues)
        queue.shift
      rescue POSIX::Mqueue::QueueEmpty
        retry
      end
    end

    private
    def queue_from_name(queue)
      queue.instance_of?(Localjob) ? queue : Localjob.new(queue)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localjob-0.0.2 lib/localjob/channel.rb