working threads with mpsc::channel

This commit is contained in:
Vladan Popovic 2022-07-06 20:33:43 +02:00
parent d023f5db76
commit 7bfd37b799
5 changed files with 221 additions and 105 deletions

17
src/gps.rs Normal file
View file

@ -0,0 +1,17 @@
use anyhow;
use std::sync::mpsc::SyncSender;
use std::thread;
use std::time::Duration;
use crate::modem::Msg;
pub fn main(sender: SyncSender<Msg>) -> Result<(), anyhow::Error> {
println!("entering GPS sender loop ...");
for i in 0..20 {
println!("sending GPS message ({}) of 20 ...", i);
let _ = sender.send(Msg::Location("{\"lat\": 20.4322, \"long\": 44.5432}".to_string()))?;
thread::sleep(Duration::from_millis(2000));
}
Ok(())
}