Created
April 9, 2017 13:21
-
-
Save MrSpock/4552870f792c17743514ced7a4c38199 to your computer and use it in GitHub Desktop.
Thread issue
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
// launch thread inside main() | |
let th = thread::spawn(move || { | |
select! { | |
msg = rx.recv() => { | |
println!("{:?}", msg); | |
} | |
} | |
// }; | |
}); | |
// launch tokio-core service | |
l.run(server::Server { | |
socket: socket, | |
buf: vec![0; 1024], | |
to_read: None, | |
// start thread with MQTT code and then provide tx channel here | |
mqtt_channel: Some(tx), | |
}) | |
.unwrap(); | |
//inide Server impl | |
match self.mqtt_channel { | |
Some(ref tx) => { | |
// println!("Got status msg from {}", peer); | |
// println!("{:?}", apc::UPS::decode(&data)); | |
// tx.send(apc::UPS::decode(&data)).unwrap(); | |
// let tx_ch = tx.clone(); | |
let msg = apc::UPS::decode(&data); | |
match tx.send(msg) { | |
Ok(_) => {} | |
Err(e) => { | |
println!("Channel send error: {}", e); | |
} | |
} | |
} | |
None => { | |
println!("Message received but no service to take action"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment