Add corex library with resource-aware execution primitives
CI / Rustfmt (push) Canceled after 0s
CI / Clippy (push) Canceled after 0s
CI / Test (default features) (push) Canceled after 0s
CI / Test (all features) (push) Canceled after 0s
CI / Test (bg only) (push) Canceled after 0s
CI / Test (compute only) (push) Canceled after 0s
CI / Test (io only) (push) Canceled after 0s
CI / Run example (push) Canceled after 0s
CI / Docs check (push) Canceled after 0s
CI / Cargo package dry-run (push) Canceled after 0s
CI / Rustfmt (push) Canceled after 0s
CI / Clippy (push) Canceled after 0s
CI / Test (default features) (push) Canceled after 0s
CI / Test (all features) (push) Canceled after 0s
CI / Test (bg only) (push) Canceled after 0s
CI / Test (compute only) (push) Canceled after 0s
CI / Test (io only) (push) Canceled after 0s
CI / Run example (push) Canceled after 0s
CI / Docs check (push) Canceled after 0s
CI / Cargo package dry-run (push) Canceled after 0s
- Implement CI workflow for formatting, linting, testing, and documentation checks. - Create publish workflow for automated publishing to crates.io. - Add .gitignore to exclude build artifacts and editor files. - Define Cargo.toml for corex and corex-core with dependencies and metadata. - Add README.md files for corex and corex-core with usage instructions and licensing. - Implement core execution primitives: spawn_io, compute, and spawn_bg with panic isolation. - Establish global engine context for resource management based on logical CPU cores. - Introduce error handling for compute panics.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//! Demonstrates `corex`'s three execution primitives end to end, including
|
||||
//! automatic recovery from a panicking compute closure.
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let ctx = corex::init();
|
||||
println!(
|
||||
"engine context: io_threads={} compute_threads={} bg_concurrency={}",
|
||||
ctx.io_threads, ctx.compute_threads, ctx.bg_concurrency
|
||||
);
|
||||
|
||||
let io_handle = corex::spawn_io(async {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
||||
42u64
|
||||
});
|
||||
|
||||
let sum_result = corex::compute(|| (1..=1_000u64).sum::<u64>());
|
||||
|
||||
let panic_result: Result<u64, corex::CorexError> = corex::compute(|| {
|
||||
panic!("intentional panic to demonstrate isolation");
|
||||
});
|
||||
|
||||
let recovery_result = corex::compute(|| 2u64 + 2u64);
|
||||
|
||||
let bg_handle = corex::spawn_bg(async {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||
"bg-task-done"
|
||||
})
|
||||
.await;
|
||||
|
||||
let io_value = io_handle.await.expect("io task panicked");
|
||||
let bg_value = bg_handle.await.expect("bg task panicked");
|
||||
|
||||
println!("spawn_io result: {io_value}");
|
||||
println!("compute sum result: {sum_result:?}");
|
||||
println!("compute panic-isolation result: {panic_result:?}");
|
||||
println!("compute pool still usable after panic: {recovery_result:?}");
|
||||
println!("spawn_bg result: {bg_value}");
|
||||
}
|
||||
Reference in New Issue
Block a user