#aio #async #futures #libaio

libaio-futures

Straightforward Linux AIO using Futures/async/await

13 releases

0.2.2 Jan 19, 2021
0.2.1 Jan 13, 2021
0.1.9 Dec 31, 2020
0.1.7 Jun 22, 2020

#176 in Asynchronous

Download history 19/week @ 2020-11-06 3/week @ 2020-11-13 5/week @ 2020-11-20 13/week @ 2020-11-27 12/week @ 2020-12-04 5/week @ 2020-12-11 1/week @ 2020-12-18 50/week @ 2020-12-25 33/week @ 2021-01-01 56/week @ 2021-01-08 48/week @ 2021-01-15 14/week @ 2021-01-22 4/week @ 2021-01-29 7/week @ 2021-02-05 210/week @ 2021-02-12 17/week @ 2021-02-19

81 downloads per month
Used in growth-ring

MIT license

37KB
769 lines


lib.rs:

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

~790KB
~15K SLoC