Skip to main content

PersistentChild

Struct PersistentChild 

Source
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: Child

The 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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.