def pop_up_to(num_to_pop = 1, opts = {})
      case opts
      when TrueClass, FalseClass
        non_bock = opts
      when Hash
        timeout = opts.fetch(:timeout, nil)
        non_block = opts.fetch(:non_block, false)
      end

      handle_interrupt do
        @mutex.synchronize do
          while true
            if @que.empty?
              if non_block
                raise ThreadError, "queue empty"
              else
                begin
                  @num_waiting += 1
                  @cond.wait(@mutex, timeout)
                  return nil if @que.empty?
                ensure
                  @num_waiting -= 1
                end
              end
            else
              return @que.shift(num_to_pop)
            end
          end
        end
      end
    end
def pop_up_to(num_to_pop = 1, opts = {})
      case opts
      when TrueClass, FalseClass
        non_bock = opts
      when Hash
        timeout = opts.fetch(:timeout, nil)
        non_block = opts.fetch(:non_block, false)
      end

      handle_interrupt do
        @mutex.synchronize do
          while true
            if @que.empty?
              if non_block
                raise ThreadError, "queue empty"
              else
                begin
                  @num_waiting += 1
                  @cond.wait(@mutex, timeout)
                  return nil if @que.empty?
                ensure
                  @num_waiting -= 1
                end
              end
            else
              return @que.shift(num_to_pop)
            end
          end
        end
      end
    end
Retrieves data from the queue and returns array of contents.
 If +num_to_pop+ are available in the queue then multiple elements are returned in array response
 If the queue is empty, the calling thread is
 suspended until data is pushed onto the queue.  If +non_block+ is true, the
 thread isn't suspended, and an exception is raised.