Sha256: 254607969ca7d3ef635f104293aa60c929952e2d2e98a4a6965bed3a16319f35

Contents?: true

Size: 478 Bytes

Versions: 2

Compression:

Stored size: 478 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
      (queue,), = IO.select(@queues)
      queue.shift
    rescue POSIX::Mqueue::QueueEmpty
      retry
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
localjob-0.1.0 lib/localjob/channel.rb
localjob-0.0.1 lib/localjob/channel.rb