garnix-io / cradle Goto Github PK
View Code? Open in Web Editor NEWLicense: BSD 3-Clause "New" or "Revised" License
License: BSD 3-Clause "New" or "Revised" License
We briefly discussed this already, but I thought I'd bring up the related set of issues that are streaming, returning handles rather than files, and async execution of processes.
One option that we came up with is passing the consumer as an argument. But there are a couple more:
AsyncOutput
class. Instead of instances for Exit
and Stdout
, for example, it might have instances for Async Exit
and StdoutHandle
. It would, I imagine, be called with a different function that run
(e.g., start
).Output
instances for Async Exit
, StdoutHandle
etc, but expanding the class so extractOutput
has a signature of Either ProcessStarted ProcessResult -> output
instead of just ProcessResult -> output
. If any output is async, then we get a Left. This likely isn't safe, in the sense that having e.g. (ExitCode, StdoutHandle)
might just be an error.Stdout
).It's probably sensible to just put on all these questions, but I was thinking a bit about this and wanted to just jot down ideas.
Currently the output Output
s (StdoutTrimmed
, StdoutUntrimmed
, Stderr
) return bytestrings. The idea then is that users will call conversion functions themselves.
There are, I think, several problems with this:
hGetEncoding
)What I propose instead is:
hSetBinaryMode True
on the handleStd(out/err)Text
, with trimmed and untrimmed variants. This behaves like the functions in Data.Text.IO
; that is, it uses the locale encoding and converts from that (potentially just directly using the Data.Text.IO
functionsStdoutUtf8
and StdoutLatin1
(with trimmed variants?), which set the encoding of the handle to the respective encoding, and use the corresponding encoding/decoding functions in Data.Text
.It'd be helpful to compare this tool with similar ones:
process
typed-process
turtle
shelly
shake
I tried using cradle
to write a helper for limiting system resources with systemd, but ran into the problem that only the Cradle
module is exposed, and that doesn't expose the Input
class method, or the ProcessConfig
type. I think those should be re-exported from somewhere. But more importantly, maybe all modules should be exposed, even if with an Internal
name? Otherwise anyone who has an unforeseen use case has to fork the library.
For stdout, there's StdoutTrimmed
and StdoutUntrimmed
. For stderr there's just Stderr
(which is untrimmed). Is there a reason for this, or should they be unified.
As I mentioned in another issue, I was hoping to write a SystemdRunLimits
Input
, and a couple of questions came up:
Input
a class? All of the inputs are just representing ProcessConfiguration -> ProcessConfiguration
functions. So they could just be combined via <>
rather than anything fancier. E.g.:run (cmd "mycmd" <> args ["arg1", "arg2"] <> stdinHandle hdl <> workingDir "some-dir")
Type inference would improve, the codebase would be simpler, and the types much easier to read.
run
(instead of an Input
)? The disadvantages are that a clearly wrong use of run
typechecks but throws a runtime error, and that other Inputs
that may want to modify the command (e.g.: a Sudo
Input
), now have to be run in a very specific order which is opaque to the user (and, to me at least, it's harder to read or understand what each command is doing).(Combined with 2 the above example would be:
run "mycmd" ["arg1", "arg2"] (stdinHandle hdl <> workingDir "some-dir")
And run :: (MonadIO m, Output a) => String -> [String] -> (ProcessConfig -> ProcessConfig) -> m a
(though having a newtype for ProcessConfig -> ProcessConfig
might be nice).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.