I'm starting to get into non-blocking IO, and my first real project with it is based on using Java's NIO system in the standard library in a non-blocking manner. In essence, it is like a normal stream with read/write methods, but they all instantly return always, with some nice library facilities to make this easy to work with. I'm wondering what Rust crate(s) are best to get a similar experience in Rust. Notably, I'm not looking for C#-style async/await, which I can find for Rust, but rather Java/NIO style with instantly-returning networking functions.
I'm not too familiar with NIO, but perhaps the mio crate is what you are looking for?
If I remember my Java 8 stuff correctly, Java NIO and other future libs are "callback" based, i.e. the call immediately returns and your callbacks are triggered when the IO is done or throws exception.
That is a different async model from Rust's, you probably already figured out, where "async / await" kind of mimics the sync flow, except
.await are the points when the (re)scheduling happens. (I don't know about C#).
To support a similar behavior of Java NIO, I think you can look into
executor in Rust async ecosystem. My personal favorite is a crate called
smol and its related crates.
Oh so it's callback based. Callbacks are so cumbersome to use in Rust that there's no such library, but it could be built on top of async/await.
@keepsimple1 stuff like Tokio or smol fall into the category of C#-style async await.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.