Skip to content

Commit

Permalink
Refactor: Use OneshotSenderOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Miaxos committed Feb 29, 2024
1 parent 6fb723b commit aa97ec0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion openraft/src/core/raft_msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::type_config::alias::AsyncRuntimeOf;
use crate::type_config::alias::LogIdOf;
use crate::type_config::alias::NodeIdOf;
use crate::type_config::alias::NodeOf;
use crate::type_config::alias::OneshotSenderOf;
use crate::type_config::alias::SnapshotDataOf;
use crate::AsyncRuntime;
use crate::ChangeMembers;
Expand All @@ -28,7 +29,7 @@ use crate::Vote;
pub(crate) mod external_command;

/// A oneshot TX to send result from `RaftCore` to external caller, e.g. `Raft::append_entries`.
pub(crate) type ResultSender<C, T, E = Infallible> = <AsyncRuntimeOf<C> as AsyncRuntime>::OneshotSender<Result<T, E>>;
pub(crate) type ResultSender<C, T, E = Infallible> = OneshotSenderOf<C, Result<T, E>>;

pub(crate) type ResultReceiver<C, T, E = Infallible> =
<AsyncRuntimeOf<C> as AsyncRuntime>::OneshotReceiver<Result<T, E>>;
Expand Down
3 changes: 2 additions & 1 deletion openraft/src/raft/raft_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::error::RaftError;
use crate::metrics::RaftDataMetrics;
use crate::metrics::RaftServerMetrics;
use crate::raft::core_state::CoreState;
use crate::type_config::alias::OneshotSenderOf;
use crate::AsyncRuntime;
use crate::Config;
use crate::MessageSummary;
Expand All @@ -39,7 +40,7 @@ where C: RaftTypeConfig

// TODO(xp): it does not need to be a async mutex.
#[allow(clippy::type_complexity)]
pub(in crate::raft) tx_shutdown: Mutex<Option<<C::AsyncRuntime as AsyncRuntime>::OneshotSender<()>>>,
pub(in crate::raft) tx_shutdown: Mutex<Option<OneshotSenderOf<C, ()>>>,
pub(in crate::raft) core_state: Mutex<CoreState<C::NodeId, C::AsyncRuntime>>,

/// The ongoing snapshot transmission.
Expand Down
6 changes: 3 additions & 3 deletions openraft/src/storage/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::sync::oneshot;

use crate::async_runtime::AsyncOneshotSendExt;
use crate::display_ext::DisplayOption;
use crate::AsyncRuntime;
use crate::type_config::alias::OneshotSenderOf;
use crate::LogId;
use crate::RaftTypeConfig;
use crate::StorageIOError;
Expand All @@ -16,15 +16,15 @@ pub struct LogFlushed<C>
where C: RaftTypeConfig
{
last_log_id: Option<LogId<C::NodeId>>,
tx: <C::AsyncRuntime as AsyncRuntime>::OneshotSender<Result<Option<LogId<C::NodeId>>, io::Error>>,
tx: OneshotSenderOf<C, Result<Option<LogId<C::NodeId>>, io::Error>>,
}

impl<C> LogFlushed<C>
where C: RaftTypeConfig
{
pub(crate) fn new(
last_log_id: Option<LogId<C::NodeId>>,
tx: <C::AsyncRuntime as AsyncRuntime>::OneshotSender<Result<Option<LogId<C::NodeId>>, io::Error>>,
tx: OneshotSenderOf<C, Result<Option<LogId<C::NodeId>>, io::Error>>,
) -> Self {
Self { last_log_id, tx }
}
Expand Down

0 comments on commit aa97ec0

Please sign in to comment.