diff --git a/openraft/src/async_runtime.rs b/openraft/src/async_runtime.rs index a83ae4378..a71a485b0 100644 --- a/openraft/src/async_runtime.rs +++ b/openraft/src/async_runtime.rs @@ -49,7 +49,7 @@ pub trait AsyncRuntime: Debug + Default + PartialEq + Eq + OptionalSend + Option type ThreadLocalRng: rand::Rng; /// Type of a `oneshot` sender. - type OneshotSender: AsyncOneshotSendExt + OptionalSend + OptionalSync + Debug + Sized; + type OneshotSender: OneshotSender + OptionalSend + OptionalSync + Sized; /// Type of a `oneshot` receiver error. type OneshotReceiverError: std::error::Error + OptionalSend; @@ -104,8 +104,6 @@ pub trait AsyncRuntime: Debug + Default + PartialEq + Eq + OptionalSend + Option #[derive(Debug, Default, PartialEq, Eq)] pub struct TokioRuntime; -pub struct TokioOneShotSender(pub tokio::sync::oneshot::Sender); - impl AsyncRuntime for TokioRuntime { type JoinError = tokio::task::JoinError; type JoinHandle = tokio::task::JoinHandle; @@ -114,7 +112,7 @@ impl AsyncRuntime for TokioRuntime { type TimeoutError = tokio::time::error::Elapsed; type Timeout + OptionalSend> = tokio::time::Timeout; type ThreadLocalRng = rand::rngs::ThreadRng; - type OneshotSender = TokioOneShotSender; + type OneshotSender = tokio::sync::oneshot::Sender; type OneshotReceiver = tokio::sync::oneshot::Receiver; type OneshotReceiverError = tokio::sync::oneshot::error::RecvError; @@ -168,11 +166,11 @@ impl AsyncRuntime for TokioRuntime { fn oneshot() -> (Self::OneshotSender, Self::OneshotReceiver) where T: OptionalSend { let (tx, rx) = tokio::sync::oneshot::channel(); - (TokioOneShotSender(tx), rx) + (tx, rx) } } -pub trait AsyncOneshotSendExt { +pub trait OneshotSender { /// Attempts to send a value on this channel, returning it back if it could /// not be sent. /// @@ -184,15 +182,9 @@ pub trait AsyncOneshotSendExt { fn send(self, t: T) -> Result<(), T>; } -impl AsyncOneshotSendExt for TokioOneShotSender { +impl OneshotSender for tokio::sync::oneshot::Sender { #[inline] fn send(self, t: T) -> Result<(), T> { - self.0.send(t) - } -} - -impl Debug for TokioOneShotSender { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("TokioSendWrapper").finish() + self.send(t) } } diff --git a/openraft/src/core/raft_core.rs b/openraft/src/core/raft_core.rs index 7d3b2f6a1..d7f814528 100644 --- a/openraft/src/core/raft_core.rs +++ b/openraft/src/core/raft_core.rs @@ -20,7 +20,7 @@ use tracing::Instrument; use tracing::Level; use tracing::Span; -use crate::async_runtime::AsyncOneshotSendExt; +use crate::async_runtime::OneshotSender; use crate::config::Config; use crate::config::RuntimeConfig; use crate::core::balancer::Balancer; diff --git a/openraft/src/core/sm/worker.rs b/openraft/src/core/sm/worker.rs index ae431bd36..b259a5f2a 100644 --- a/openraft/src/core/sm/worker.rs +++ b/openraft/src/core/sm/worker.rs @@ -1,6 +1,6 @@ use tokio::sync::mpsc; -use crate::async_runtime::AsyncOneshotSendExt; +use crate::async_runtime::OneshotSender; use crate::core::notify::Notify; use crate::core::raft_msg::ResultSender; use crate::core::sm::handle::Handle; diff --git a/openraft/src/engine/command.rs b/openraft/src/engine/command.rs index 1c4c6dfcb..4160ca2f8 100644 --- a/openraft/src/engine/command.rs +++ b/openraft/src/engine/command.rs @@ -1,6 +1,7 @@ +use std::fmt; use std::fmt::Debug; -use crate::async_runtime::AsyncOneshotSendExt; +use crate::async_runtime::OneshotSender; use crate::core::sm; use crate::engine::CommandKind; use crate::error::Infallible; @@ -244,7 +245,6 @@ where C: RaftTypeConfig } } -#[derive(Debug)] pub(crate) struct ValueSender where T: Debug + PartialEq + Eq + OptionalSend, @@ -254,6 +254,16 @@ where tx: OneshotSenderOf, } +impl Debug for ValueSender +where + T: Debug + PartialEq + Eq + OptionalSend, + C: RaftTypeConfig, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ValueSender").field("value", &self.value).finish() + } +} + impl PartialEq for ValueSender where T: Debug + PartialEq + Eq + OptionalSend, diff --git a/openraft/src/raft/mod.rs b/openraft/src/raft/mod.rs index 7c4bdb9f9..db3305e02 100644 --- a/openraft/src/raft/mod.rs +++ b/openraft/src/raft/mod.rs @@ -47,7 +47,7 @@ use tracing::trace_span; use tracing::Instrument; use tracing::Level; -use crate::async_runtime::AsyncOneshotSendExt; +use crate::async_runtime::OneshotSender; use crate::config::Config; use crate::config::RuntimeConfig; use crate::core::command_state::CommandState; diff --git a/openraft/src/raft/responder/impls.rs b/openraft/src/raft/responder/impls.rs index 9569cfb15..819768c79 100644 --- a/openraft/src/raft/responder/impls.rs +++ b/openraft/src/raft/responder/impls.rs @@ -1,4 +1,4 @@ -use crate::async_runtime::AsyncOneshotSendExt; +use crate::async_runtime::OneshotSender; use crate::raft::message::ClientWriteResult; use crate::raft::responder::Responder; use crate::type_config::alias::OneshotReceiverOf; diff --git a/openraft/src/storage/callback.rs b/openraft/src/storage/callback.rs index 033558275..3ab9c7d3a 100644 --- a/openraft/src/storage/callback.rs +++ b/openraft/src/storage/callback.rs @@ -4,7 +4,7 @@ use std::io; use tokio::sync::oneshot; -use crate::async_runtime::AsyncOneshotSendExt; +use crate::async_runtime::OneshotSender; use crate::raft_state::io_state::log_io_id::LogIOId; use crate::type_config::alias::OneshotSenderOf; use crate::LogId; diff --git a/openraft/src/timer/timeout_test.rs b/openraft/src/timer/timeout_test.rs index 445ebd51a..b9ccc48d4 100644 --- a/openraft/src/timer/timeout_test.rs +++ b/openraft/src/timer/timeout_test.rs @@ -3,7 +3,6 @@ use std::time::Duration; use tokio::time::sleep; use tokio::time::Instant; -use crate::async_runtime::AsyncOneshotSendExt; use crate::timer::timeout::RaftTimer; use crate::timer::Timeout; use crate::AsyncRuntime;