Reusing futures-rs channel on a reactor


#1

Hi. I’m using a channel to pass data to my eventloop thread which does n/w writes. Now if the network disconnects, I need to reconnect it and use the same channel with the new framed to forward the messages. Below is my pseudo code

fn start() -> Result<()> {
    let mut main_loop = Core::new().unwrap();

    let (mut tx1, rx1) = mpsc::channel::<i32>(16);

    thread::spawn(move || {
        for i in 0..10 {
            tx1 = tx1.send(i).wait().unwrap();
            thread::sleep(Duration::new(1, 0));
        }
        thread::sleep(Duration::from_millis(10000));
    });

    let future_rx = rx1.for_each(|num| {
            println!("{:?}", num);
            Ok(())
    });

    let future_rx = future_rx.boxed();

    loop {
        //
        // reconnect to the server and return a new `framed`
        //
        // let (sender, receiver) = framed.split();
        // let future_rx = future_rx.forward(sender);

        let _ = main_loop.run(future_rx);
    }
    Ok(())
}

If there is an error, main_loop errors out and reconnection happens generating a new framed
How do I reuse the existingfuture_rx (and send backlog messages in the channel)