RustyLee: Starts Heart organ processing
Activates the Heart organ's main command processing loop by calling its `start` method. Replaces the previous placeholder `run_loop` method with the functional `start` method. The `start` method now takes a mutable reference to `self`, which enables it to operate as a long-running process without consuming the `Heart` instance.
This commit is contained in:
parent
7633985535
commit
dbb52ccbb2
2 changed files with 4 additions and 12 deletions
|
|
@ -10,12 +10,6 @@ pub struct Heart {
|
||||||
feedback_to_brain_tx: mpsc::Sender<BrainMessage>,
|
feedback_to_brain_tx: mpsc::Sender<BrainMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Heart {
|
|
||||||
pub(crate) fn run_loop(&mut self) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Heart {
|
impl Heart {
|
||||||
pub(crate) fn new(id: u32, rx: Receiver<OrganCommandEnvelope>, tx: Sender<BrainMessage>) -> Self {
|
pub(crate) fn new(id: u32, rx: Receiver<OrganCommandEnvelope>, tx: Sender<BrainMessage>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -24,11 +18,9 @@ impl Heart {
|
||||||
feedback_to_brain_tx: tx,
|
feedback_to_brain_tx: tx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Heart {
|
|
||||||
#[instrument(skip(self), fields(heart_id = self.id))]
|
#[instrument(skip(self), fields(heart_id = self.id))]
|
||||||
pub fn start(self) {
|
pub fn start(&mut self) {
|
||||||
info!("Heart listener active");
|
info!("Heart listener active");
|
||||||
|
|
||||||
while let Ok(envelope) = self.brain_command_rx.recv() {
|
while let Ok(envelope) = self.brain_command_rx.recv() {
|
||||||
|
|
@ -53,4 +45,4 @@ impl Heart {
|
||||||
let _ = self.feedback_to_brain_tx.send(reply);
|
let _ = self.feedback_to_brain_tx.send(reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ impl OrganFactory {
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut heart = Heart::new(id, brain_command_to_organ_rx, feedback_to_brain_tx);
|
let mut heart = Heart::new(id, brain_command_to_organ_rx, feedback_to_brain_tx);
|
||||||
heart.run_loop();
|
heart.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket
|
socket
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue