Open PaulThompson opened 4 years ago
I think this would solve the problem in https://github.com/denoland/deno/issues/2494 — using OS-level pipes between the child processes (with no copying through the parent Deno process) would work exactly like shell piping, and when the writing process quits and closes its stdout
, the reading process will detect this on its stdin
the usual way.
I propose idea of an additional builtin function
Deno.pipe
to open a new anonymous pipe. The call result ultimately would provide two resource ids which could be used to assemble process pipelines.The key benefit compared to alternatives:
Deno.run
with stdout and stdin using the piped option & usingDeno.copy
to copy between one stdout and the next stdin: Using direct "anonymous" pipes between child processes means that the data would not be handled in the deno process. It therefore would use less CPU.mkfifo
and opening the fifo for read and write usingDeno.read
andDeno.write
: Using an anonymous pipe avoids having to expose the pipe to the filesystem (cleanup issues, security issues?, inconvenient), avoids platform dependent hacks.Deno.run({cmd:'bash','-c','process1 | process2'})
: Using an anonymous pipe in the deno process avoids the overhead and inconvenience of a shell subprocess.Use case sketch:
The proposed function could have types as follows:
The implementation in rust would be to call one of the platform depdendent functions for create an anonymous pipe eg https://github.com/rust-lang/rust/blob/f4e4485a052857e5dd32ea29ceb7b1a8223e83cc/library/std/src/sys/unix/pipe.rs#L12
or https://github.com/rust-lang/rust/blob/f4e4485a052857e5dd32ea29ceb7b1a8223e83cc/library/std/src/sys/windows/pipe.rs#L48 etc
Note:
piped
io options onDeno.run
already internally create anonymous pipes for reading/writing stdio. (Intokio::process::Command
andstd::process::Command
). In order to pipe between two processes it needs an API to create the anonymous pipes separately from the processes.Deno.run
option for stdio to & from a resource id number works.