Refactor replies module

This commit is contained in:
Joscha 2024-12-05 14:09:01 +01:00
parent 096df5d9fa
commit 2a8b466fa1
3 changed files with 6 additions and 12 deletions

View file

@ -8,6 +8,7 @@ caseless = "0.2.1"
jiff = { version = "0.1.15", default-features = false, features = ["std"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
tokio = { version = "1.42.0", features = ["sync", "time"] }
unicode-normalization = "0.1.24"
[lints]

View file

@ -1,5 +1,6 @@
pub mod api;
mod emoji;
pub mod nick;
mod replies;
pub use crate::emoji::Emoji;

View file

@ -1,10 +1,6 @@
use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
use std::time::Duration;
use std::{error, result};
use std::{collections::HashMap, error, fmt, hash::Hash, result, time::Duration};
use tokio::sync::oneshot::{self, Receiver, Sender};
use tokio::sync::oneshot;
#[derive(Debug)]
pub enum Error {
@ -28,7 +24,7 @@ pub type Result<T> = result::Result<T, Error>;
#[derive(Debug)]
pub struct PendingReply<R> {
timeout: Duration,
result: Receiver<R>,
result: oneshot::Receiver<R>,
}
impl<R> PendingReply<R> {
@ -44,7 +40,7 @@ impl<R> PendingReply<R> {
#[derive(Debug)]
pub struct Replies<I, R> {
timeout: Duration,
pending: HashMap<I, Sender<R>>,
pending: HashMap<I, oneshot::Sender<R>>,
}
impl<I, R> Replies<I, R> {
@ -55,10 +51,6 @@ impl<I, R> Replies<I, R> {
}
}
pub fn timeout(&self) -> Duration {
self.timeout
}
pub fn wait_for(&mut self, id: I) -> PendingReply<R>
where
I: Eq + Hash,