Files
mytheclipse/crates/corex-core/src/io.rs
T
asepharyana d8144e249e Add corex library with resource-aware execution primitives
- 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.
2026-08-28 16:05:04 +07:00

32 lines
863 B
Rust

//! Async I/O task spawning, instrumented with [`tracing`].
use tracing::Instrument;
/// Spawns `future` onto the ambient Tokio runtime, wrapped in a
/// `corex_io_task` tracing span.
///
/// # Panics
///
/// Panics if called outside the context of a running Tokio runtime; corex
/// does not construct or own a runtime of its own, it schedules onto
/// whichever runtime the caller is already inside.
pub fn spawn_io<F>(future: F) -> tokio::task::JoinHandle<F::Output>
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static,
{
let span = tracing::info_span!("corex_io_task");
tokio::spawn(future.instrument(span))
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn spawn_io_roundtrips_a_value() {
let handle = spawn_io(async { 7u32 });
assert_eq!(handle.await.unwrap(), 7);
}
}