1use bevy_ecs::prelude::*;
2use futures::stream::Empty;
3use tokio::sync::mpsc::error::TryRecvError;
4
5use crate::component::resource::component_connection::{
6 ComponentConfig, ComponentConnection, IncomingStanza,
7};
8
9pub fn receive_stanzas(
10 mut conn: ResMut<ComponentConnection>,
11 mut messages: MessageWriter<IncomingStanza>,
12 config: Res<ComponentConfig>,
13) {
14 let mut count = 0;
15 while count < config.max_stanzas_per_tick {
16 println!("About to pull another stanza off the stack!");
17 match conn.incoming_rx.try_recv() {
18 Ok(stanza) => {
19 messages.write(IncomingStanza(stanza));
20 count += 1;
21 }
22 Err(TryRecvError::Empty) => {
23 info!("Empty incoming stream!")
24 }
25 Err(TryRecvError::Disconnected) => {
26 panic!()
27 }
28 }
29 }
30}