hirura/hrr_rb_ssh

View on GitHub
lib/hrr_rb_ssh/compat/ruby/queue.rb

Summary

Maintainability
A
25 mins
Test Coverage
if RUBY_VERSION < "2.3"
  class ClosedQueueError < StandardError
  end

  class Queue
    alias_method :__enq__, :enq
    alias_method :__deq__, :deq

    def close
      @closed = true
    end

    def closed?
      @closed == true
    end

    def enq arg
      raise ClosedQueueError if @closed == true
      __enq__ arg
    end

    def deq
      begin
        Timeout.timeout(0.1) do
          __deq__
        end
      rescue Timeout::Error
        return nil if @closed == true
        retry
      end
    end
  end
end