use crate::{Command, Error};
use tokio::sync::mpsc::Sender;
#[derive(Debug, Clone)]
pub struct NetworkService {
command_sender: Sender<Command>,
}
impl NetworkService {
pub const fn new(command_sender: Sender<Command>) -> Self {
Self { command_sender }
}
pub async fn send_command(
&mut self,
command: Command,
) -> Result<(), Error> {
self.command_sender
.send(command)
.await
.map_err(|e| Error::CommandSend(e.to_string()))
}
pub fn sender(&self) -> Sender<Command> {
self.command_sender.clone()
}
}