product-os-async-executor 0.0.20

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 Rust 1.81+ 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) to be used 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.

Feature Flags

Feature Default Description
exec_async_std no Enables: async-std, async-std/default
exec_embassy no Enables: embassy-executor, embassy-time
exec_smol no Enables: smol
exec_tokio no Enables: tokio, tokio/time, tokio/rt
hyper_executor no Hyper integration — pair with an exec_* feature (e.g. exec_tokio)
moment no Time abstraction utilities

default features: chrono/clock

Installation

[dependencies]
product-os-async-executor = "0.0.1"

Pin the version to match the crate Cargo.toml when using path or git dependencies.

Documentation

Full API documentation is available at docs.rs/product-os-async-executor.

Usage

Overview

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.

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.20", 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() {
    // 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
}

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

Contributing

Contributions are not currently available but will be available on a public repository soon.

License

This project is licensed under the GNU GPLv3.