use libp2p::futures::StreamExt;
use tokio_stream::wrappers::WatchStream;
use tracing::error;
mod handle_shoji_command;
mod handle_swarm_event;
use crate::Satellite;
impl Satellite {
pub async fn run(mut self) -> ! {
let mut event_stream = WatchStream::new(self.event_watcher.clone());
let mut shoji = self.create_shoji();
loop {
tokio::select! {
Some(event) = self.swarm.0.next() => {
if let Err(e) = self.handle_swarm_event(event) {
error!("Handling swarm events failed: {}", e);
}
}
Some(command) = self.shoji_command_reciever.recv() => {
if let Err(e) = self.handle_shoji_command(command) {
error!("Handling shoji's commands failed: {}", e);
}
}
Some(event) = event_stream.next() => {
for module in &self.config.modules {
let mut module = module.lock().await;
module.on_events(
event.clone(),
&mut shoji
).await;
}
}
}
}
}
}