Sha256: d60512246d381099d657d89de27d16ec7551cc7dffb169ff9e7f56a84f48ad31

Contents?: true

Size: 885 Bytes

Versions: 13

Compression:

Stored size: 885 Bytes

Contents

module DeadlySerious
  module Engine
    module BaseProcess
      def run(readers: [], writers:[])
        reader = readers.first
        @writer = writers.first

        if reader
          reader.each { |packet| super(packet.chomp) }
        else
          super()
        end
      rescue Errno::EPIPE
        # Ignore it. We expect that sometimes =)
      end

      # Send a packet to the next process
      def send(packet = nil)
        send_buffered(packet)
        flush_buffer
      end

      alias :emit :send

      # Send a packet to the next process,
      # however, accumulate some of them
      # before send to gain a little
      # efficency.
      def send_buffered(packet = nil)
        @writer << packet if packet
        @writer << "\n"
      end

      # Send all not yet sent packets.
      def flush_buffer
        @writer.flush
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
deadly_serious-0.11.0 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.10.0 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.9.5 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.9.4 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.9.3 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.9.2 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.9.1 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.9.0 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.8.1 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.8.0 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.7.0 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.6.1 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.6.0 lib/deadly_serious/engine/base_process.rb