pub struct PersistentChild {
pub child: Child,
pub stdin: Option<BufWriter<ChildStdin>>,
pub stdout: Option<InterruptReader<ChildStdout>>,
pub stderr: Option<InterruptReader<ChildStderr>>,
}Expand description
Behaves nearly identically to a regular Child, except the
stdin pipe is wrapped in a BufWriter and the stdout
and stderr pipes are wrapped in an /// InterruptReader.
The InterruptReader is similar to a BufReader in the
fact that it buffers the input bytes. However, it also comes
with the ability to be interrupted from another thread.
In Duat, this will be done right before the ConfigUnloaded
hook is triggered, signaling that Duat is about to quit/unload
the config. This will also make it so context::will_unload
starts returning true, which can be used to stop other
threads on a loop.
When you’re doing your reading loop from the stdout and
stderr, you should add a check if the return type is
Err(err) if is_interrupt(&err) in order to check for that
possibility.
The is_interrupt function just checks if the error was
sent because of the aforementioned reason.
If the error is of that type, it is your responsability to
break the reading loop and terminate the thread, so duat can
properly reload (duat won’t reload until you do so.).
Fields§
§child: ChildThe Child that was spawned.
It is guaranteed that stdin, stdout and stderr will
be None, since those will have been moved to the
PersistentChild’s version of them.
stdin: Option<BufWriter<ChildStdin>>The handle to a Child’s standard input, buffered so
you don’t have to worry about unwrapping and dealing with
yet to be flushed bytes inbetween reloads
If you wish to reuse the stdin and are running a writing
loop using the loop keyword, try to use while !context::will_unload() instead, alongside a timeout
function for receiving the data that will be sent.
stdout: Option<InterruptReader<ChildStdout>>A handle to the Child’s stdout, with buffering and
the ability to be interrupted through the
ConfigUnloaded hook.
You should check if the reading was interrupted with
is_interrupt. If that is the case, you should end your
reading loop, as Duat is about to reload the
configuration.
stderr: Option<InterruptReader<ChildStderr>>A handle to the Child’s stderr, with buffering and
the ability to be interrupted through the
ConfigUnloaded hook.
You should check if the reading was interrupted with
is_interrupt. If that is the case, you should end your
reading loop, as Duat is about to reload the
configuration.