Open nrdvana opened 8 months ago
Hello. Could you say more about what makes it hard for the application to know whether it has called start()? In other words, why would it be bad for your function to just document that it takes only started harnesses?
In general, the proposed method looks harmless and maintenance-free. On the other hand, every public API has some mental cost for users. I'm happy to have the method if it disproportionately simplifies your application.
The function is a logger of external commands, and the usual behavior is to pass it an @argv
to make its own harness, execute, and record the exit status. In some cases, I want the full features of IPC::Run pipelines, so I decided to extend its API to pass a harness object or the traditional \@argv
. But then, in some cases I want to start the harness in parallel with some other tasks so it has already been started when it reaches the logging function that finishes it and reports the command and its exit code.
If a harness was a one-shot object, this wouldn't be a problem. but because a harness can be run multiple times, it seems generally useful to inspect what state it's currently in so that that state doesn't need to be tracked externally.
I'd accept such a PR. That said, how well would the following mitigate the
trouble with using pump
?
eval { $h->pump }; die $@ if $@ and $@ ne 'process ended prematurely';
That's sort of what I did in the meantime:
# Start if it isn't already started
eval { $h->pump }
But it would look cleaner for long-term maintenance if it was
$h->start unless $h->started;
I have a situation where I want a generic function that finishes a harness and reports its result, but doesn't know if the caller started the harness yet. The module seems to be missing a "->started" accessor.
I can almost achieve this with 'pump', but that has the chance of throwing an exception if a pipe is broken.
From the code in pump, there is:
I basically just want public access to that first line, and then call
->finish
Would you accept a PR for essentially this?