refactor stop logic

This commit is contained in:
dignifiedquire
2020-03-21 19:05:50 +01:00
parent 4d6a9e4f14
commit d798356c19
4 changed files with 51 additions and 30 deletions

View File

@@ -39,13 +39,15 @@ async fn main() {
println!("info: {:#?}", info);
let ctx1 = ctx.clone();
std::thread::spawn(move || loop {
if ctx1.has_next_event() {
if let Ok(event) = ctx1.get_next_event() {
cb(event);
async_std::task::spawn(async move {
loop {
if ctx1.has_next_event() {
if let Ok(event) = ctx1.get_next_event() {
cb(event);
}
} else {
async_std::task::sleep(time::Duration::from_millis(50));
}
} else {
std::thread::sleep(time::Duration::from_millis(50));
}
});