test_executors

This crate provides extremely simple, yet useful, async executors. They are primarily useful for writing unit tests without bringing in a full-blown executor such as tokio.
Quick Start
use ;
// Run a simple async function
let result = spin_on;
assert_eq!;
// Run an async function that sleeps
let result = sleep_on;
assert_eq!;
Available Executors
The crate provides three main executors:
spin_on- Polls a future in a busy loop on the current thread. Best for CPU-bound tasks or when latency is critical.sleep_on- Polls a future on the current thread, sleeping between polls. Best for I/O-bound tasks to avoid burning CPU.spawn_on- Spawns a future on a new thread, polling it there. Best for fire-and-forget tasks.
Platform Support
Native Platforms
All executors work as described above on native platforms (Linux, macOS, Windows, etc.).
WebAssembly Support
This crate has special support for wasm32 targets:
- The
async_testmacro automatically adapts to usewasm-bindgen-teston WASM spawn_localuseswasm_bindgen_futures::spawn_localon WASM targets
Features
async_test Macro
The async_test macro allows you to write async tests that work on both native and WASM targets:
use async_test;
async
Integration with some_executor
This crate implements the some_executor trait for all executors, allowing them to be used in executor-agnostic code:
use SpinRuntime;
use SomeExecutor;
let mut runtime = new;
// Use runtime with some_executor traits
Utilities
The crate also provides utility functions and types:
poll_onceandpoll_once_pin- Poll a future exactly oncespawn_local- Platform-aware spawning that works on both native and WASMpend_forever::PendForever- A future that is always pending (useful for testing)