Sha256: 6f11c722dbb136a689c1996c9aa766c9d8c274c2b4ef7bc08ac233d4ffe52dff

Contents?: true

Size: 904 Bytes

Versions: 17

Compression:

Stored size: 904 Bytes

Contents

require 'fileutils'

module DeadlySerious
  module Engine
    module OpenIo
      def run(*args, readers: [], writers:[])
        opened_readers = readers.map { |reader| wrap_io(reader) }
        opened_writers = writers.map { |writer| wrap_io(writer) }
        super(*args, readers: opened_readers, writers: opened_writers)
      ensure
        if opened_writers
          opened_writers.each { |writer| close_io(writer) }
        end
        if opened_readers
          opened_readers.each { |reader| close_io(reader) }
        end
      end

      private

      def close_io(io)
        return unless io
        return if io.closed?
        io.close
      rescue => e
        # Intentionally eat the error
        # because it's being used inside
        # an "ensure" block
        puts e.inspect
      end

      def wrap_io(pipe_name)
        Channel.new(pipe_name).io
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
deadly_serious-0.11.0 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.10.0 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.9.5 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.9.4 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.9.3 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.9.2 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.9.1 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.9.0 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.8.1 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.8.0 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.7.0 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.6.1 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.6.0 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.5.3 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.5.2 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.5.1 lib/deadly_serious/engine/open_io.rb
deadly_serious-0.5.0 lib/deadly_serious/engine/open_io.rb