Class: Pytty::Daemon::Components::Stream
- Inherits:
-
Object
- Object
- Pytty::Daemon::Components::Stream
- Defined in:
- lib/pytty/daemon/components/stream.rb
Instance Method Summary collapse
-
#initialize(cmd:, env:) ⇒ Stream
constructor
A new instance of Stream.
- #run(stream:) ⇒ Object
Constructor Details
#initialize(cmd:, env:) ⇒ Stream
9 10 11 12 |
# File 'lib/pytty/daemon/components/stream.rb', line 9 def initialize(cmd:, env:) @cmd = cmd @env = env end |
Instance Method Details
#run(stream:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pytty/daemon/components/stream.rb', line 14 def run(stream:) pipe = IO.pipe stderr = Async::IO::Generic.new(pipe.first) stderr_writer = Async::IO::Generic.new(pipe.last) cmd, args = @cmd process_stdout, process_stdin, pid = PTY.spawn(@env, cmd, *args, err: stderr_writer.fileno) stderr_writer.close stdout = Async::IO::Generic.new process_stdout # stdin = Async::IO::Generic.new process_stdin Async::Task.current.async do |task| while c = stdout.read(1) stream.write c end stream.close end # Async::Task.current.async do |task| # loop do # p "o" # task.sleep 1 # end # end end |