task.rs

 1use futures::{Sink, SinkExt, Stream, StreamExt};
 2use tokio::sync::mpsc;
 3use tokio_xmpp::{Error, Stanza};
 4
 5pub async fn incoming_stanza_task(
 6    mut stream: impl Stream<Item = Stanza> + Unpin,
 7    tx: mpsc::Sender<Stanza>,
 8) {
 9    while let Some(stanza) = stream.next().await {
10        if tx.send(stanza).await.is_err() {
11            break;
12        }
13    }
14}
15
16pub async fn outgoing_stanza_task(
17    mut sink: impl Sink<Stanza, Error = Error> + Unpin,
18    mut rx: mpsc::Receiver<Stanza>,
19) {
20    while let Some(stanza) = rx.recv().await {
21        if sink.send(stanza).await.is_err() {
22            break;
23        }
24    }
25}