Skip to content

Instantly share code, notes, and snippets.

@MrSpock
Created April 9, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrSpock/4552870f792c17743514ced7a4c38199 to your computer and use it in GitHub Desktop.
Save MrSpock/4552870f792c17743514ced7a4c38199 to your computer and use it in GitHub Desktop.
Thread issue
// 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