Refactor replies module
This commit is contained in:
parent
55d672cddb
commit
bcedd3350d
3 changed files with 6 additions and 12 deletions
|
|
@ -8,6 +8,7 @@ caseless = "0.2.1"
|
||||||
jiff = { version = "0.1.15", default-features = false, features = ["std"] }
|
jiff = { version = "0.1.15", default-features = false, features = ["std"] }
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
serde = { version = "1.0.215", features = ["derive"] }
|
||||||
serde_json = "1.0.133"
|
serde_json = "1.0.133"
|
||||||
|
tokio = { version = "1.42.0", features = ["sync", "time"] }
|
||||||
unicode-normalization = "0.1.24"
|
unicode-normalization = "0.1.24"
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
pub mod api;
|
pub mod api;
|
||||||
mod emoji;
|
mod emoji;
|
||||||
pub mod nick;
|
pub mod nick;
|
||||||
|
mod replies;
|
||||||
|
|
||||||
pub use crate::emoji::Emoji;
|
pub use crate::emoji::Emoji;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, error, fmt, hash::Hash, result, time::Duration};
|
||||||
use std::fmt;
|
|
||||||
use std::hash::Hash;
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::{error, result};
|
|
||||||
|
|
||||||
use tokio::sync::oneshot::{self, Receiver, Sender};
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
@ -28,7 +24,7 @@ pub type Result<T> = result::Result<T, Error>;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PendingReply<R> {
|
pub struct PendingReply<R> {
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
result: Receiver<R>,
|
result: oneshot::Receiver<R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> PendingReply<R> {
|
impl<R> PendingReply<R> {
|
||||||
|
|
@ -44,7 +40,7 @@ impl<R> PendingReply<R> {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Replies<I, R> {
|
pub struct Replies<I, R> {
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
pending: HashMap<I, Sender<R>>,
|
pending: HashMap<I, oneshot::Sender<R>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I, R> Replies<I, 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>
|
pub fn wait_for(&mut self, id: I) -> PendingReply<R>
|
||||||
where
|
where
|
||||||
I: Eq + Hash,
|
I: Eq + Hash,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue