use std::env;
use std::process::Command;
use arty_executor::Executor;
const EXPECTED_FAILURE_CHILD_ENV: &str = "ARTY_EXECUTOR_EXPECTED_FAILURE_CHILD";
fn main() {
if env::var_os("IS_TESTING").is_some() && env::var_os(EXPECTED_FAILURE_CHILD_ENV).is_none() {
assert_failure_in_child();
} else {
run_example();
}
}
fn assert_failure_in_child() {
let executable = env::current_exe().expect("the running example necessarily has a current executable path");
let status = Command::new(executable)
.env(EXPECTED_FAILURE_CHILD_ENV, "1")
.status()
.expect("the example executable that is already running must be startable as a child");
assert!(!status.success(), "the child example must terminate after the task panic");
}
#[expect(clippy::panic, reason = "the example demonstrates executor behavior when a task panics")]
fn run_example() {
let executor = unsafe { Executor::builder().build() };
let tasks = executor.tasks();
tasks.add(async move {
panic!("Panic from the async task!");
});
_ = executor.execute_cycle();
unreachable!("The process should have terminated by now due to the panic.");
}