rename various sender/receiver variables to be clearer
This commit is contained in:
parent
4d5a412395
commit
544974117f
18
src/lib.rs
18
src/lib.rs
@ -49,34 +49,34 @@ impl Tenquestionmarks {
|
|||||||
|
|
||||||
pub fn run (&self) {
|
pub fn run (&self) {
|
||||||
crossbeam::scope(|scope| {
|
crossbeam::scope(|scope| {
|
||||||
// Our event channel.
|
// Our main event channel.
|
||||||
// Modules push events to tenquestionmarks using this channel.
|
// Modules push events to tenquestionmarks using this channel.
|
||||||
let (ref sender, ref receiver) = mpsc::channel();
|
let (ref main_sender, ref main_receiver) = mpsc::channel();
|
||||||
|
|
||||||
// Module threads.
|
// Module threads.
|
||||||
// Each Module will produce events which tenquestionmarks will push
|
// Each Module will produce events which tenquestionmarks will push
|
||||||
// into all other Modules.
|
// into all other Modules.
|
||||||
// tenquestionmarks propagates all events to each Module through these
|
// tenquestionmarks propagates all events to each Module through these
|
||||||
// channels.
|
// channels.
|
||||||
let senders: BTreeMap<&str, Sender<Arc<Envelope>>> = self.modules.iter().map(|(key, module)| {
|
let module_senders: BTreeMap<&str, Sender<Arc<Envelope>>> = self.modules.iter().map(|(key, module)| {
|
||||||
let module_sender = sender.clone();
|
let main_sender_clone = main_sender.clone();
|
||||||
let (sender, receiver) = mpsc::channel();
|
let (module_sender, module_receiver) = mpsc::channel();
|
||||||
info!("Spawning thread for \"{}\"", key);
|
info!("Spawning thread for \"{}\"", key);
|
||||||
scope.spawn(move || {
|
scope.spawn(move || {
|
||||||
module.run(module_sender, receiver);
|
module.run(main_sender_clone, module_receiver);
|
||||||
info!("Thread for \"{}\" is exiting", key);
|
info!("Thread for \"{}\" is exiting", key);
|
||||||
});
|
});
|
||||||
(&key[..], sender)
|
(&key[..], module_sender)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// tenquestionmarks main event loop.
|
// tenquestionmarks main event loop.
|
||||||
// tenquestionmarks receives events produced by Modules and pushes them
|
// tenquestionmarks receives events produced by Modules and pushes them
|
||||||
// into all other Modules
|
// into all other Modules
|
||||||
loop {
|
loop {
|
||||||
match receiver.recv() {
|
match main_receiver.recv() {
|
||||||
Ok(envelope) => {
|
Ok(envelope) => {
|
||||||
let arc_envelope = Arc::new(envelope);
|
let arc_envelope = Arc::new(envelope);
|
||||||
for (key, sender) in &senders {
|
for (key, sender) in &module_senders {
|
||||||
match sender.send(arc_envelope.clone()) {
|
match sender.send(arc_envelope.clone()) {
|
||||||
Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err),
|
Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err),
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user