tgusermanager.rs 692 B

1234567891011121314151617181920212223242526
  1. use tokio::sync::{mpsc, oneshot};
  2. #[derive(Debug)]
  3. pub enum TgManagerCommand {
  4. Get {
  5. user_id: String,
  6. reply_to: oneshot::Sender<String>,
  7. },
  8. }
  9. pub async fn user_manager(rx: &mut mpsc::Receiver<TgManagerCommand>) {
  10. log::info!("Request came");
  11. while let Some(cmd) = rx.recv().await {
  12. use TgManagerCommand::*;
  13. log::info!("Command received");
  14. match cmd {
  15. Get { user_id, reply_to } => {
  16. log::info!("{}", format!("Get command found, sending {}", user_id));
  17. reply_to
  18. .send(format!("You've requested {}", user_id))
  19. .unwrap();
  20. }
  21. }
  22. }
  23. }