Sha256: ef2c77b5fff0fa639bbe8338186be7ef6f815b44adea70b1dd0b28b05177666d

Contents?: true

Size: 660 Bytes

Versions: 9

Compression:

Stored size: 660 Bytes

Contents

module Qs

  class IOPipe

    NULL = File.open('/dev/null', 'w')
    NUMBER_OF_BYTES = 1

    attr_reader :reader, :writer

    def initialize
      @reader = NULL
      @writer = NULL
    end

    def setup
      @reader, @writer = ::IO.pipe
    end

    def teardown
      @reader.close unless @reader === NULL
      @writer.close unless @writer === NULL
      @reader = NULL
      @writer = NULL
    end

    def read
      @reader.read_nonblock(NUMBER_OF_BYTES)
    end

    def write(value)
      @writer.write_nonblock(value[0, NUMBER_OF_BYTES])
    end

    def wait(timeout = nil)
      !!::IO.select([@reader], nil, nil, timeout)
    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
qs-0.8.1 lib/qs/io_pipe.rb
qs-0.8.0 lib/qs/io_pipe.rb
qs-0.7.1 lib/qs/io_pipe.rb
qs-0.7.0 lib/qs/io_pipe.rb
qs-0.6.1 lib/qs/io_pipe.rb
qs-0.6.0 lib/qs/io_pipe.rb
qs-0.5.0 lib/qs/io_pipe.rb
qs-0.4.0 lib/qs/io_pipe.rb
qs-0.3.0 lib/qs/io_pipe.rb