Sha256: e986cf98b3fde667109857c410cfdfd554a8157e2a9bf69d881c1e323b01085a

Contents?: true

Size: 806 Bytes

Versions: 4

Compression:

Stored size: 806 Bytes

Contents

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

        reader.each { |packet| super(packet.chomp) }
      end

      # Alias to #send
      def emit(packet = nil)
        send(packet)
      end

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

      # 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

4 entries across 4 versions & 1 rubygems

Version Path
deadly_serious-0.5.3 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.5.2 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.5.1 lib/deadly_serious/engine/base_process.rb
deadly_serious-0.5.0 lib/deadly_serious/engine/base_process.rb