nim-chronos
nim-chronos copied to clipboard
Implement APIs for async process I/O
Chronos needs an API for launching sub-processes and interacting with their standard input and output through AsyncPipe
. Additional APIs may be added for controlling process groups and for automatically terminating sub-processes when their parent dies.
I can port Golden's system for this if you want. It handles the buffering without any problems AFAIK, but it will be good to give it more testing.
Can you clarify what "Golden" is?
Golden is a poor-man's hyperfine that I wanted for monitoring compilation performance and the code I'm thinking of looks like this:
https://github.com/disruptek/golden/blob/master/src/golden/invoke.nim
It calls startProcess
and then uses the selectors
to monitor the streams and whether the process has terminated. After removing the code to monitor cpu/clock time, the implementation is very simple.
Well, @cheatfate also has his own process I/O library based on asyncdispatch: https://github.com/cheatfate/asynctools/blob/master/asynctools/asyncproc.nim
Your chances of merging PRs here will be significantly enhanced if you take his existing code into consideration :)
I also hope that @timotheecour is going to release his private lib for process I/O inspired by D's interfaces. We don't want to repeat the same mistakes as the std lib when designing this API.
Can you explain how asyncproc
is insufficient to meet the requirement? Does it merely need to be copied and massaged into Chronos?
asyncproc
requires some procedures which chronos
do not have, tricks with RegisterWaitForSingleObject
, https://github.com/nim-lang/Nim/blob/devel/lib/pure/asyncdispatch.nim#L1002-L1018
Also AsyncPipe
is not needed actually we can use StreamTransport
instances.
can this implementation be reused here? https://github.com/yglukhov/asyncthreadpool/blob/main/asyncthreadpool/private/pipes.nim
#374