Replies: 1 comment 5 replies
-
Perhaps you are looking for something like this? tokio::join!(
s.another_select(),
async {
loop {
select! {
_ = interval_3s.tick() => {
println!("run: interval_3s");
}
_ = interval_sleep.tick() => {
println!("run: interval_sleep");
// during this time, no other arms interrupt which is ideal
time::sleep(Duration::from_secs(5)).await;
println!("run: interval_sleep + 5s");
}
}
}
}
) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to encapsulate the inner
select!
as a single entry point so that the outerselect!
don't need to explicitly handle every arm in the innerselect!
. However, if the body of an arm in the innerselect!
happens toawait
, theawait
will yield and let otherselect!
arms interrupt the body. Worse still, the lines after theawait
won't be called at all.I don't want any code (
interval_3s.tick()
in this case) in the sametokio::spawn
/task to preempt my encapsulated code (s
in this case).A raw workaround is to break the encapsulation and merge the
another_select
to theselect!
underrun
. But what if I have private members being used inanother_select
? Should they also be exposed and made public?Beta Was this translation helpful? Give feedback.
All reactions