Crate aiur

source ·
Expand description

Single thread executor library for building async runtimes.

Note: as for now it is more a research project rather then production ready library.

The async/await machinery in Rust compiler in a nutshell provides a transformation of a synchronous looking code into the struct that impls std::future::Future and then user need a library to run such future (or “poll the future to completion”). Popular async runtime libraries are tokio, async-std, smol.

The library that runs the future (usually with something called block_on() function) can have two distinct parts in its API:

  • executor - something that organizes the futures from user into a set of tasks for execution (like spawn(), JoinHandle)

  • reactor - schedule I/O using OS API (epoll, io_uring, completion port) and be able awake a task when certain I/O event occurs.

This library implements the executor part of the async runtime. Suppose I would like to create async runtime named Mega. I can do it using the aiur crate:

  1. Create a crate mega_runtime that depends aiur
  2. Implement aiur::Reactor in MegaReactor and API to schedule I/O
  3. Now I can have a type MegaRuntime = aiur::Runtime<MegaReactor>, which is now a complete runtime with both executor and reactor.
  4. Apps are using MegaRuntime not knowing anything that there is some aiur used under the hood.

As aiur does not have anything OS-specific, it can be used on any OS with std. For testing purposes it has toy reactor that only supports async sleeping.

Major distinction from popular libraries that aiur only provides a single thread executor. It seems to be a lager topic and can be discussed later.

There other ideas where ongoing research happens:

  • structured concurrency
  • async destruction
  • nostd

Modules

Macros

This is a help macro to create API for your own runtime based on re-exporting aiur runtime and specialize it with your reactor.
Waits concurrently until all futures are completed.
Waits concurrently until all futures are completed as tasks.
Creates AnyOfN stream from supplied futures.
Pins the stack variable.
Makes a pinned version of AnyOfN stream.

Structs

Stream to poll several futures concurrently.
EventId is a reactor’s id for the event that was awoken.
Data structure required to schedule IO in reactor. In order to schedule any event in reactor the EventId is required and the only way to create EventId is to create it from this structure.
The receiving half of the channel created by channel() function.
The receiving half of the oneshot channel created by oneshot() function.
The owner of the reactor (I/O event queue) and executor (task management) data structures.
The sending half of the channel created by channel() function.
The sending half of the oneshot channel created by oneshot() function.
ToyReactor is reactor that can only schedule timers.
A C-like callback which is a pointer to logger function and data.

Enums

Used as result of AnyOfN::next() for two futures.
Used as result of AnyOfN::next() for three futures.
Used as result of AnyOfN::next() for four futures.
Used as result of AnyOfN::next() for five futures.
Used as result of AnyOfN::next() for six futures.
Used as result of AnyOfN::next() for seven futures.
Used as result of AnyOfN::next() for eight futures.

Traits

A helper trait to solve the lifetime problem for with_runtime().
Reactor API for Executor.
Reactor with a very basic timers.

Functions

Creates the AnyOfN stream to poll two futures.
Creates the AnyOfN stream to poll three futures.
Creates the AnyOfN stream to poll four futures.
Creates the AnyOfN stream to poll five futures.
Creates the AnyOfN stream to poll six futures.
Creates the AnyOfN stream to poll seven futures.
Creates the AnyOfN stream to poll eigth futures.
Creates a new asynchronous channel returning the pair of (Sender, Receiver).
Polls two futures concurrently until both are completed.
Polls three futures concurrently until all are completed.
Polls four futures concurrently until all are completed.
Polls five futures concurrently until all are completed.
Polls six futures concurrently until all are completed.
Polls seven futures concurrently until all are completed.
Polls eight futures concurrently until all are completed.
Polls two futures concurrently as tasks until both are completed.
Polls three futures concurrently as tasks until both are completed.
Polls four futures concurrently as tasks until both are completed.
Polls five futures concurrently as tasks until both are completed.
Polls six futures concurrently as tasks until both are completed.
Polls seven futures concurrently as tasks until both are completed.
Polls eight futures concurrently as tasks until both are completed.
Creates a new oneshot channel and returns the pair of (sender, receiver).
Performs the async sleep.
This is how you run an async function with aiur.