product-os-async-executor 0.0.18

Product OS : Async Executor provides a set of tools to handle async execution generically so that the desired async library (e.g. tokio, smol) to be used can be chosen at compile time.
Documentation

Product OS : Async Executor

Crates.io Documentation License: GPL-3.0

Product OS : Async Executor provides a set of tools to handle async execution generically so that the desired async library (e.g. Tokio, Smol, Async-std) can be chosen at compile time.

What is Product OS?

Product OS is a collection of packages that provide different tools and features that can work together to build products more easily for the Rust ecosystem.

Features

  • Generic Executor Traits: Define common interfaces for working with different async runtimes
  • Runtime Support: Out-of-the-box support for Tokio, Smol, and Async-std
  • Timer Support: One-time and interval timers that work across runtimes
  • Async I/O Traits: AsyncRead and AsyncWrite traits for cross-runtime I/O
  • No-std Support: Works in no_std environments with alloc
  • Hyper Integration: Optional executor integration for Hyper

Installation

Add Product OS : Async Executor to your Cargo.toml:

[dependencies]
product-os-async-executor = { version = "0.0.17", features = ["exec_tokio"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "time"] }

Quick Start

Using with Tokio

use product_os_async_executor::{Executor, ExecutorPerform, TokioExecutor};

#[tokio::main]
async fn main() {
    // Create an executor context
    let executor = TokioExecutor::context().await.unwrap();
    
    // Spawn a task
    let result = TokioExecutor::spawn_in_context(async {
        42
    }).await;
    
    assert!(result.is_ok());
}

Using Timers

use product_os_async_executor::{Timer, TokioExecutor};

#[tokio::main]
async fn main() {
    // Create an interval timer that fires every 100ms
    let mut timer = TokioExecutor::interval(100).await;
    
    // Wait for the first tick
    let elapsed = timer.tick().await;
    println!("Elapsed: {}ms", elapsed);
}

Feature Flags

  • default: Minimal no_std support with alloc and clock
  • exec_tokio: Enable Tokio executor support
  • exec_smol: Enable Smol executor support
  • exec_async_std: Enable Async-std executor support
  • exec_embassy: Enable Embassy executor support (embedded)
  • moment: Enable time abstraction utilities
  • hyper_executor: Enable Hyper executor integration

Core Traits

Executor

The Executor trait provides a unified interface for creating and managing executor contexts:

use product_os_async_executor::{Executor, TokioExecutor};

#[tokio::main]
async fn main() {
    let executor = TokioExecutor::context().await.unwrap();
    executor.enter_context().await;
}

ExecutorPerform

The ExecutorPerform trait provides methods for spawning and blocking on tasks:

use product_os_async_executor::{ExecutorPerform, TokioExecutor};

#[tokio::main]
async fn main() {
    let task = TokioExecutor::spawn_in_context(async {
        println!("Hello from spawned task!");
        42
    }).await;
    
    assert!(task.is_ok());
}

Timer

The Timer trait provides cross-runtime timer functionality:

use product_os_async_executor::{Timer, TokioExecutor};

#[tokio::main]
async fn main() {
    // One-shot timer
    let mut once = TokioExecutor::once(1000).await;
    once.tick().await; // Waits ~1 second
    
    // Interval timer
    let mut interval = TokioExecutor::interval(100).await;
    interval.tick().await; // Waits ~100ms
}

Testing

# Run tests with Tokio executor
cargo test --features exec_tokio

# Run tests with all features
cargo test --all-features

# Generate documentation
cargo doc --all-features --open

License

GNU GPLv3

Contributing

Contributions are welcome! Please ensure:

  • All tests pass: cargo test --all-features
  • Code is formatted: cargo fmt
  • No clippy warnings: cargo clippy --all-features
  • Documentation is updated for public APIs

Minimum Supported Rust Version (MSRV)

Rust 1.69 or later.