Expand description
§Luminal
Luminal is a high-performance async runtime designed to solve tokio’s DLL boundary issues while maintaining similar performance and API compatibility.
§Key Features
- DLL Boundary Safe: Unlike tokio, Luminal doesn’t rely on thread-local storage, making it 100% safe to pass across DLL boundaries
- Explicit Handle Passing: All runtime context is explicit rather than implicit via TLS
- Drop-in Replacement: Provides tokio-compatible APIs like
spawn,block_on, andJoinHandle - Cross-Platform: Works on Windows, Linux, and macOS
- Multi-threaded: Uses a work-stealing scheduler with multiple worker threads for optimal CPU utilization
- Efficient Work Stealing: Implements a sophisticated work-stealing algorithm to distribute tasks evenly across worker threads
- Memory Efficient: Minimizes allocations and memory overhead in the task scheduling system
- No-std Support: Can run in
no_stdenvironments withallocfor embedded and constrained systems
§Basic Usage
use luminal::Runtime;
async fn hello_world() {
println!("Hello, world!");
}
fn main() {
let rt = Runtime::new().unwrap();
let rt_clone = rt.clone();
rt.block_on(async move {
rt_clone.spawn(hello_world()).await;
});
}§Explicit Runtime Usage
use luminal::Runtime;
fn main() {
let rt = Runtime::new().unwrap();
rt.block_on(async {
println!("Running on Luminal runtime!");
});
}§DLL Boundary Safety
Unlike tokio, which uses thread-local storage for its runtime context, Luminal uses explicit context passing. This makes it safe to use across DLL boundaries:
// Inside a DLL
fn dll_function(runtime: luminal::Runtime) -> u32 {
// Safe to use the runtime passed from outside
runtime.block_on(async { 42 })
}
// From the main application
fn main() {
let rt = luminal::Runtime::new().unwrap();
let result = dll_function(rt.clone());
assert_eq!(result, 42);
}Re-exports§
pub use runtime::Runtime;pub use runtime::Handle;pub use runtime::JoinHandle;pub use runtime::Executor;pub use runtime::spawn;pub use runtime::block_on;pub use error::RuntimeError;