#aio #future #async #libaio

yanked firewood-libaio

Straightforward Linux AIO using Futures/async/await

2 releases

0.0.2 Apr 21, 2023
0.0.1 Apr 14, 2023

#11 in #aio

42 downloads per month
Used in 2 crates

MIT license

37KB
747 lines

Straightforward Linux AIO using Futures/async/await.

Example

Use aiofut to schedule writes to a file:

use futures::{executor::LocalPool, future::FutureExt, task::LocalSpawnExt};
use aiofut::AIOBuilder;
use std::os::unix::io::AsRawFd;
let mut aiomgr = AIOBuilder::default().build().unwrap();
let file = std::fs::OpenOptions::new()
    .read(true)
    .write(true)
    .create(true)
    .truncate(true)
    .open("test")
    .unwrap();
let fd = file.as_raw_fd();
// keep all returned futures in a vector
let ws = vec![(0, "hello"), (5, "world"), (2, "xxxx")]
    .into_iter()
    .map(|(off, s)| aiomgr.write(fd, off, s.as_bytes().into(), None))
    .collect::<Vec<_>>();
// here we use futures::executor::LocalPool to poll all futures
let mut pool = LocalPool::new();
let spawner = pool.spawner();
for w in ws.into_iter() {
    let h = spawner.spawn_local_with_handle(w).unwrap().map(|r| {
        println!("wrote {} bytes", r.0.unwrap());
    });
    spawner.spawn_local(h).unwrap();
}
pool.run();

Dependencies

~0.7–6.5MB
~17K SLoC