https://github.com/bells307/asynk-rt
Rust multithread asynchronous runtime and reactor
https://github.com/bells307/asynk-rt
rust rust-async rust-runtime
Last synced: 5 months ago
JSON representation
Rust multithread asynchronous runtime and reactor
- Host: GitHub
- URL: https://github.com/bells307/asynk-rt
- Owner: bells307
- Created: 2024-04-01T07:54:27.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-03T05:50:41.000Z (over 1 year ago)
- Last Synced: 2025-09-29T03:13:47.398Z (9 months ago)
- Topics: rust, rust-async, rust-runtime
- Language: Rust
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# asynk
Rust multithread asynchronous runtime and reactor
## Example
```rust
use futures::future;
use futures_timer::Delay;
use std::{
sync::{
atomic::{AtomicU32, Ordering},
Arc,
},
time::Duration,
};
fn main() {
asynk::builder().build().unwrap();
asynk::block_on(main_future()).unwrap();
}
async fn main_future() {
let val = Arc::new(AtomicU32::new(0));
let expected_val = 10_000;
let handles = (0..expected_val)
.map(|_| Arc::clone(&val))
.map(|val| {
asynk::spawn(async move {
// some computations ...
Delay::new(Duration::from_secs(1)).await;
val.fetch_add(1, Ordering::SeqCst);
})
})
.collect::>();
future::join_all(handles).await;
assert_eq!(val.load(Ordering::SeqCst), expected_val);
}
```
# asynk-hyper
[Hyper](https://github.com/hyperium/hyper) integration with `asynk` runtime
## Example
```rust
use asynk_hyper::TcpListener;
use futures::StreamExt;
use http_body_util::Full;
use hyper::{body::Bytes, server::conn::http1, service::service_fn, Request, Response};
use std::convert::Infallible;
const SERVER_SOCK_ADDR: &str = "127.0.0.1:8040";
fn main() {
asynk::builder().build().unwrap();
asynk::block_on(server()).unwrap();
}
async fn server() {
let addr = SERVER_SOCK_ADDR.parse().unwrap();
let listener = TcpListener::bind(addr).unwrap();
let mut accept = listener.accept();
while let Some(res) = accept.next().await {
// Spawn new task for the connection
asynk::spawn(async move {
// Accept the connection
let (stream, _) = res.unwrap();
if let Err(e) = http1::Builder::new()
.serve_connection(stream, service_fn(hello))
.await
{
eprintln!("error serving connection: {:?}", e);
}
});
}
}
async fn hello(_: Request) -> Result>, Infallible> {
Ok(Response::new(Full::new(Bytes::from(
"
Hello, World!
",
))))
}
```