Sha256: d004f444688f357b765d53fe03e02fd1612e2714ca8d78cf8dab7e70663e7f2e

Contents?: true

Size: 672 Bytes

Versions: 7

Compression:

Stored size: 672 Bytes

Contents

module BackgroundProcess::IOHelpers
  extend self
  def detect(streams = [], timeout = nil, &block)
    begin
      Timeout::timeout(timeout) do
        # Something that should be interrupted if it takes too much time...
        until streams.empty?
          active_streams, _, _ = Kernel.select(streams, nil, nil, 1)
          active_streams.each do |s|
            (streams -= [s]; next) if s.eof?
            content = s.gets
            if result = (block.arity == 1 ? yield(content) : yield(s, content))
              return result
            end
          end if active_streams
        end
      end
      nil
    rescue Timeout::Error
      nil
    end

  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
background_process-1.3 lib/background_process/io_helpers.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/background_process-1.2/lib/background_process/io_helpers.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/background_process-1.2/lib/background_process/io_helpers.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/background_process-1.2/lib/background_process/io_helpers.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/background_process-1.2/lib/background_process/io_helpers.rb
background_process-1.2 lib/background_process/io_helpers.rb
background_process-1.1 lib/background_process/io_helpers.rb