1use crate::{Command, Error};
5
6use tokio::sync::mpsc::Sender;
7
8#[derive(Debug, Clone)]
10pub struct NetworkService {
11 command_sender: Sender<Command>,
13}
14
15impl NetworkService {
16 pub const fn new(command_sender: Sender<Command>) -> Self {
18 Self { command_sender }
19 }
20
21 pub async fn send_command(
23 &mut self,
24 command: Command,
25 ) -> Result<(), Error> {
26 self.command_sender
27 .send(command)
28 .await
29 .map_err(|e| Error::CommandSend(e.to_string()))
30 }
31
32 pub fn sender(&self) -> Sender<Command> {
34 self.command_sender.clone()
35 }
36}