-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sync primitives to AsyncRuntime
trait
#1013
Comments
👋 Thanks for opening this issue! Get help or engage by:
|
I would like to share the things I found while drafting the support for Monoio:) To make Openraft implementation (not tests) runtime-agnostic (#249)If we merge #1204, we still need these from Tokio:
Add Monoio support for Openraft - Primitive support
I implemented a draft version of Monoio support there, since the reason/situation listed above, for primitives like Primitive support of various runtimes
I would say Tokio's ecosystem is huge, other runtimes are relatively immature and thus primarily concentrating on core I/O part. For Openraft, we should definitely add more generic needed primitives to |
It's a great road map! Thank you! About Mutex: I think some of the About As we discussed before, there will be a feature flag to control if Openraft adds a default Tokio runtime to The |
Yes, this is fairly easily possible. Fortunately, However, what does NOT work from Regarding
+1 :-), then we don't have any remaining dependency left. |
The only Thus |
This is neat!
Get it:)
Yeah, this is unfortunate:<
Great, tokio usage -=1 😁 |
Noticed that |
The |
There is |
It looks like just pin them then it is working with the following approach: use std::pin::pin;
#[tokio::main]
async fn main() {
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<()>();
let fu = rx.recv();
let sleep = tokio::time::sleep(std::time::Duration::from_secs(1));
let fpin = pin!(fu);
let spin = pin!(sleep);
futures::future::select(fpin, spin).await;
} |
But why do you want to avoid using use std::pin::pin;
use futures::future::FutureExt;
#[tokio::main]
async fn main() {
let (_tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<()>();
let sleep = tokio::time::sleep(std::time::Duration::from_secs(1));
loop {
futures::select_biased!(
_ = rx.recv().fuse() => {
println!("recv completed");
break;
}
_ = sleep.fuse() => {
println!("sleep completed");
break;
}
);
}
} |
Right, |
Yes. Tokio primitives do work in other runtimes, but they are not optimally-supported.
For example, Tokio has its own counters for cooperative multitasking (which, obviously, only make sense and are active if running within Tokio), other runtimes have their own algorithm for how not to block the runtime for too long. The same is true for resource monitoring support (e.g., via
tracing
in Tokio).Another issue is that Tokio sync primitives allocate memory at unexpected points. This is OK if you are fine with your program going broken on OOM, but we don't have this luxury :-). We need to handle OOMs properly.
Originally posted by @schreter in #1010 (review)
TODO:
AsyncRuntime::oneshot
#1023AsyncRuntime
channel interfaces #1198AsyncRuntime::unbounded_mpsc
#1162AsyncRuntime::watch
#1163The text was updated successfully, but these errors were encountered: