Function async_process::driver

source ·
pub fn driver() -> impl Future<Output = Infallible> + Send + 'static
Expand description

Runs the driver for the asynchronous processes.

This future takes control of global structures related to driving Children and reaping zombie processes. These responsibilities include listening for the SIGCHLD signal and making sure zombie processes are successfully waited on.

If multiple tasks run driver() at once, only one will actually drive the reaper; the other ones will just sleep. If a task that is driving the reaper is dropped, a previously sleeping task will take over. If all tasks driving the reaper are dropped, the “async-process” thread will be spawned. The “async-process” thread just blocks on this future and will automatically be spawned if no tasks are driving the reaper once a Child is created.

This future will never complete. It is intended to be ran on a background task in your executor of choice.

§Examples

use async_executor::Executor;
use async_process::{driver, Command};

// Create an executor and run on it.
let ex = Executor::new();
ex.run(async {
    // Run the driver future in the background.
    ex.spawn(driver()).detach();

    // Run a command.
    Command::new("ls").output().await.ok();
}).await;