pub async fn supervise_signals<F>(wait_hook: F)
where
    F: Future<Output = ()>,
{
    let mut supervisor = SUPERVISOR_RUNNING.lock().await;

    if !supervisor.is_some() {
        supervisor.replace(());
        drop(supervisor)
    } else {
        wait_hook.await;
        return;
    }

    let mut interrupt = tokio::signal::unix::signal(SignalKind::interrupt()).unwrap();
    let mut terminate = tokio::signal::unix::signal(SignalKind::terminate()).unwrap();

    tokio::select! {
    _ = interrupt.recv() => {},
    _ = terminate.recv() => {},
    };

    eprintln!("eggshell: signal received, tearing down containers");

    let mut lock = EGGSHELLS.lock().await.clone();

    let mut i = 0;
    let mut prune_indexes = Vec::new();

    for shell in lock.iter_mut() {
        if let Err(e) = shell.teardown().await {
            eprintln!("error during teardown: {:?}", e);
        } else {
            prune_indexes.push(i)
        }
        i += 1;
    }

    for idx in prune_indexes {
        lock.remove(idx);
    }

    wait_hook.await;

    if lock.len() == 0 {
        std::process::abort()
    }
}
/// Please call this function in your tests with tokio::spawn() to handle signals being sent to
/// your tests. A wait function can be supplied to perform any final settling before terminating
/// the test program.
///
/// In the event multiple signal handlers are spawned, N+1 handlers will simply run the wait hook
/// and return. Only the first execution is responsible for reaping all eggshells.
///
/// ```
/// use eggshell::supervise_signals;
/// use std::time::Duration;
/// use tokio::{runtime::Handle, time::sleep};
///
/// fn signal_handler() {
///     let handle = Handle::current();
///     handle.spawn(supervise_signals(async { sleep(Duration::new(1, 0)).await; }));
/// }
/// ```
Please call this function in your tests with tokio::spawn() to handle signals being sent to
your tests. A wait function can be supplied to perform any final settling before terminating
the test program.

In the event multiple signal handlers are spawned, N+1 handlers will simply run the wait hook
and return. Only the first execution is responsible for reaping all eggshells.




Please call this function in your tests with tokio :: spawn () to handle signals being sent to your tests . A wait function can be supplied to perform any final settling before terminating the test program . In the event multiple signal handlers are spawned N + 1 handlers will simply run the wait hook and return . Only the first execution is responsible for reaping all eggshells .
pub async fn supervise_signals<F>(wait_hook: F)
where
    F: Future<Output = ()>,
{
    let mut supervisor = SUPERVISOR_RUNNING.lock().await;
    if !supervisor.is_some() {
        supervisor.replace(());
        drop(supervisor)
    } else {
        wait_hook.await;
        return;
    }
    let mut interrupt = tokio::signal::unix::signal(SignalKind::interrupt()).unwrap();
    let mut terminate = tokio::signal::unix::signal(SignalKind::terminate()).unwrap();
    tokio::select! {
    _ = interrupt.recv() => {},
    _ = terminate.recv() => {},
    };
    eprintln!("eggshell: signal received, tearing down containers");
    let mut lock = EGGSHELLS.lock().await.clone();
    let mut i = 0;
    let mut prune_indexes = Vec::new();
    for shell in lock.iter_mut() {
        if let Err(e) = shell.teardown().await {
            eprintln!("error during teardown: {:?}", e);
        } else {
            prune_indexes.push(i)
        }
        i += 1;
    }
    for idx in prune_indexes {
        lock.remove(idx);
    }
    wait_hook.await;
    if lock.len() == 0 {
        std::process::abort()
    }
}
pub async fn supervise_signals < F > ( wait_hook : F ) where F : Future < Output = ( ) > , { let mut supervisor = SUPERVISOR_RUNNING . lock ( ) . await ; if ! supervisor . is_some ( ) { supervisor . replace ( ( ) ) ; drop ( supervisor ) } else { wait_hook . await ; return ; } let mut interrupt = tokio :: signal :: unix :: signal ( SignalKind :: interrupt ( ) ) . unwrap ( ) ; let mut terminate = tokio :: signal :: unix :: signal ( SignalKind :: terminate ( ) ) . unwrap ( ) ; tokio :: select ! { interrupt recv ( ) { } terminate recv ( ) { } } ; eprintln ! ( " " ) ; let mut lock = EGGSHELLS . lock ( ) . await . clone ( ) ; let mut i = 0 ; let mut prune_indexes = Vec :: new ( ) ; for shell in lock . iter_mut ( ) { if let Err ( e ) = shell . teardown ( ) . await { eprintln ! ( " " e ) ; } else { prune_indexes . push ( i ) } i += 1 ; } for idx in prune_indexes { lock . remove ( idx ) ; } wait_hook . await ; if lock . len ( ) == 0 { std :: process :: abort ( ) } }
Please call this function in your tests with tokio::spawn() to handle signals being sent to
your tests.
Please call this function in your tests with tokio :: spawn () to handle signals being sent to your tests .
wait_hook
F
wait_hook
F