async fn handle_output(
    file_path: Option<PathBuf>,
    verbose: bool,
    mut rx: mpsc::Receiver<Link>,
    task_limit: usize,
) -> Result<(), String> {
    let mut senders = Vec::new();
    let mut handlers = Vec::new();
    if let Some(x) = file_path {
        let (tx, rx) = mpsc::channel::<Link>(task_limit);
        senders.push(tx);
        let handler = tokio::spawn(async move { file_handler::write_links(x, rx).await });
        handlers.push(handler);
    }
    if verbose {
        let (tx, rx) = mpsc::channel::<Link>(task_limit);
        senders.push(tx);
        let handler = tokio::spawn(async move { write_standard_output(rx).await });
        handlers.push(handler);
    }
    while let Some(link) = rx.recv().await {
        for i in &senders {
            if let Err(_) = i.send(link.clone()).await {
                let _ = futures::future::try_join_all(handlers).await;
                return Err("Something Wrong with IO".to_string());
            }
        }
    }

    senders.clear();

    let handle = futures::future::try_join_all(handlers).await;
    match handle {
        Err(x) => Err(x.to_string()),
        Ok(_) => Ok(()),
    }
}
/// Funtion to handle the output. Handles both console and file output.
/// Outputs in JSON format.
Funtion to handle the output. Handles both console and file output.
Outputs in JSON format.
Funtion to handle the output . Handles both console and file output . Outputs in JSON format .
async fn handle_output(
    file_path: Option<PathBuf>,
    verbose: bool,
    mut rx: mpsc::Receiver<Link>,
    task_limit: usize,
) -> Result<(), String> {
    let mut senders = Vec::new();
    let mut handlers = Vec::new();
    if let Some(x) = file_path {
        let (tx, rx) = mpsc::channel::<Link>(task_limit);
        senders.push(tx);
        let handler = tokio::spawn(async move { file_handler::write_links(x, rx).await });
        handlers.push(handler);
    }
    if verbose {
        let (tx, rx) = mpsc::channel::<Link>(task_limit);
        senders.push(tx);
        let handler = tokio::spawn(async move { write_standard_output(rx).await });
        handlers.push(handler);
    }
    while let Some(link) = rx.recv().await {
        for i in &senders {
            if let Err(_) = i.send(link.clone()).await {
                let _ = futures::future::try_join_all(handlers).await;
                return Err("Something Wrong with IO".to_string());
            }
        }
    }
    senders.clear();
    let handle = futures::future::try_join_all(handlers).await;
    match handle {
        Err(x) => Err(x.to_string()),
        Ok(_) => Ok(()),
    }
}
async fn handle_output ( file_path : Option < PathBuf > , verbose : bool , mut rx : mpsc :: Receiver < Link > , task_limit : usize , ) -> Result < ( ) , String > { let mut senders = Vec :: new ( ) ; let mut handlers = Vec :: new ( ) ; if let Some ( x ) = file_path { let ( tx , rx ) = mpsc :: channel :: < Link > ( task_limit ) ; senders . push ( tx ) ; let handler = tokio :: spawn ( async move { file_handler :: write_links ( x , rx ) . await } ) ; handlers . push ( handler ) ; } if verbose { let ( tx , rx ) = mpsc :: channel :: < Link > ( task_limit ) ; senders . push ( tx ) ; let handler = tokio :: spawn ( async move { write_standard_output ( rx ) . await } ) ; handlers . push ( handler ) ; } while let Some ( link ) = rx . recv ( ) . await { for i in & senders { if let Err ( _ ) = i . send ( link . clone ( ) ) . await { let _ = futures :: future :: try_join_all ( handlers ) . await ; return Err ( " " . to_string ( ) ) ; } } } senders . clear ( ) ; let handle = futures :: future :: try_join_all ( handlers ) . await ; match handle { Err ( x ) => Err ( x . to_string ( ) ) , Ok ( _ ) => Ok ( ( ) ) , } }
Funtion to handle the output.
Funtion to handle the output .
file_path
Option<PathBuf>
verbose
bool
rx
mpsc::Receiver<Link>
task_limit
usize
file_path
Option<PathBuf>
verbose
bool
rx
mpsc::Receiver<Link>
task_limit
usize