-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: move state machine Handle and Worker into separate files
- Loading branch information
1 parent
29cefe5
commit bb75f7b
Showing
6 changed files
with
243 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! State machine control handle | ||
use tokio::sync::mpsc; | ||
|
||
use crate::alias::JoinHandleOf; | ||
use crate::core::sm::Command; | ||
use crate::RaftTypeConfig; | ||
|
||
/// State machine worker handle for sending command to it. | ||
pub(crate) struct Handle<C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(in crate::core::sm) cmd_tx: mpsc::UnboundedSender<Command<C>>, | ||
|
||
#[allow(dead_code)] | ||
pub(in crate::core::sm) join_handle: JoinHandleOf<C, ()>, | ||
} | ||
|
||
impl<C> Handle<C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(crate) fn send(&mut self, cmd: Command<C>) -> Result<(), mpsc::error::SendError<Command<C>>> { | ||
tracing::debug!("sending command to state machine worker: {:?}", cmd); | ||
self.cmd_tx.send(cmd) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.