scatter_net/legacy/interaction/implementations/
terminate.rs

1use iroh::endpoint::VarInt;
2
3use crate::{spawn_and_forget, Interaction, Terminate};
4
5impl<E, R> Terminate<E, R> for Interaction
6where
7    E: Into<VarInt> + Send,
8    R: AsRef<[u8]> + Send,
9{
10    fn terminate(&self, error_code: E, _reason: &R) {
11        let interaction = self.clone();
12        let error_code = error_code.into();
13
14        spawn_and_forget(async move {
15            interaction.send_stream.lock().await.finish()?;
16
17            interaction.recv_stream.lock().await.stop(error_code)?;
18
19            Ok(())
20        });
21    }
22}