pub async fn ctrl_c_with_exit_handler<F, R>(connect_future: F, exit_handler: tokio::sync::oneshot::Sender<()>) -> Result<Option<R>, CaptivePortalError>
    where
        F: std::future::Future<Output=Result<R, CaptivePortalError>>,
        R: Sized,
{
    let ctrlc = ctrl_c();
    pin_utils::pin_mut!(ctrlc);
    pin_utils::pin_mut!(connect_future);

    let r = try_select(connect_future, ctrlc).await;
    match r {
        Err(e) => {
            if let Either::Left((e, _)) = e {
                return Err(e);
            }
        }
        Ok(v) => {
            match v {
                Either::Left((v, _)) => {
                    return Ok(Some(v));
                }
                Either::Right((_, w)) => {
                    // Ctrl+C invoked. Send exit signal and await future
                    exit_handler.send(()).map_err(|_e| CaptivePortalError::Generic("Failed to use ctrl_c exit handler".to_owned()))?;
                    return Ok(Some(w.await?));
                }
            }
        }
    }

    info!("SIGKILL: Graceful shutdown initialized ...");
    Ok(None)
}
/// Wraps the given future with a ctrl+c signal listener. Returns None if the signal got caught
/// and Some(return_value) otherwise.
Wraps the given future with a ctrl+c signal listener. Returns None if the signal got caught
and Some(return_value) otherwise.
Wraps the given future with a ctrl + c signal listener . Returns None if the signal got caught and Some ( return_value ) otherwise .
pub async fn ctrl_c_with_exit_handler<F, R>(connect_future: F, exit_handler: tokio::sync::oneshot::Sender<()>) -> Result<Option<R>, CaptivePortalError>
    where
        F: std::future::Future<Output=Result<R, CaptivePortalError>>,
        R: Sized,
{
    let ctrlc = ctrl_c();
    pin_utils::pin_mut!(ctrlc);
    pin_utils::pin_mut!(connect_future);
    let r = try_select(connect_future, ctrlc).await;
    match r {
        Err(e) => {
            if let Either::Left((e, _)) = e {
                return Err(e);
            }
        }
        Ok(v) => {
            match v {
                Either::Left((v, _)) => {
                    return Ok(Some(v));
                }
                Either::Right((_, w)) => {
                    // Ctrl+C invoked. Send exit signal and await future
                    exit_handler.send(()).map_err(|_e| CaptivePortalError::Generic("Failed to use ctrl_c exit handler".to_owned()))?;
                    return Ok(Some(w.await?));
                }
            }
        }
    }
    info!("SIGKILL: Graceful shutdown initialized ...");
    Ok(None)
}
pub async fn ctrl_c_with_exit_handler < F , R > ( connect_future : F , exit_handler : tokio :: sync :: oneshot :: Sender < ( ) > ) -> Result < Option < R > , CaptivePortalError > where F : std :: future :: Future < Output = Result < R , CaptivePortalError > > , R : Sized , { let ctrlc = ctrl_c ( ) ; pin_utils :: pin_mut ! ( ctrlc ) ; pin_utils :: pin_mut ! ( connect_future ) ; let r = try_select ( connect_future , ctrlc ) . await ; match r { Err ( e ) => { if let Either :: Left ( ( e , _ ) ) = e { return Err ( e ) ; } } Ok ( v ) => { match v { Either :: Left ( ( v , _ ) ) => { return Ok ( Some ( v ) ) ; } Either :: Right ( ( _ , w ) ) => { // Ctrl+C invoked. Send exit signal and await future exit_handler . send ( ( ) ) . map_err ( | _e | CaptivePortalError :: Generic ( " " . to_owned ( ) ) ) ? ; return Ok ( Some ( w . await ? ) ) ; } } } } info ! ( " " ) ; Ok ( None ) }
Wraps the given future with a ctrl+c signal listener.
Wraps the given future with a ctrl + c signal listener .
connect_future
F
exit_handler
tokio::sync::oneshot::Sender<()>
connect_future
F
exit_handler
tokio::sync::oneshot::Sender<()>