| Crates.io | ruloom |
| lib.rs | ruloom |
| version | 0.1.2 |
| created_at | 2024-12-16 13:21:35.900081+00 |
| updated_at | 2024-12-16 22:09:07.106919+00 |
| description | A thin wrapper around 'corosensei' that provides support for stackful coroutines in Rust (like Loom in Java or goroutines in golang). |
| homepage | |
| repository | https://github.com/cronosun/ruloom |
| max_upload_size | |
| id | 1484989 |
| size | 36,527 |
It is a Crate, which is intended to simplify asynchronous programming. You can write asynchronous code as if it were synchronous code. The name is a combination of "Rust" (ru) and "Loom" (see https://wiki.openjdk.org/display/loom/Main).
https://docs.rs/ruloom/latest/ruloom/
I love Rust, but am unhappy about how asynchronous programming is solved in Rust (currently). Although there have been big improvements recently (2024) (see https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html), the situation in Rust is still not satisfactory (my opinion).
In my opinion, Rust should have taken a different path:
ruloom solve?Ruloom is based on corosensei and allows asynchronous code to be written as if it were synchronous code.
// See, no 'async' keyword here.
// This is how you you write your application / library.
fn looks_like_a_sync_function_but_its_async() {
// A future
let future = smol::Timer::after(Duration::from_millis(10));
// Await the future (suspends the current task)
await_future(future);
}
// You can the use smol or tokio to run your code / library / application.
fn run() {
smol::block_on(async {
// convert back to a future.
let future = to_future(||looks_like_a_sync_function_but_its_async());
future.await;
})
}
The two main functions of ruloom are:
await_future: Converts a future into a synchronous call. May only be used within
to_future. Technical detail: If the future is pending, the current coroutine is suspended (stack switch).to_future: Converts a synchronous function into a future. This future can then be executed
by the selected runtime (Tokio, Smol, ...).ruloom not solve?It still does not offer a std-library, you still have a dependency on a certain runtime (like Tokio or Smol).
Furthermore, you have to be careful not to call any blocking functions.
Also, ruloom is (currently) an experiment; it is certainly not advisable to use this code in production.
ruloom is just a thin wrapper around this library.Licensed under either of:
Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0) MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT) at your option.