Skip to main content

iris_core/
runtime.rs

1//! Iris 异步运行时封装
2//!
3//! 基于 Tokio 的多线程运行时,提供跨平台的异步任务调度。
4//! 主模块逻辑已内联在 [`crate::Context`] 中,此模块提供额外工具函数。
5
6#![allow(missing_docs)]
7
8use std::future::Future;
9
10/// 在 Iris 运行时句柄上 spawn 一个异步任务。
11///
12/// 需要传入 [`tokio::runtime::Handle`],通常通过 [`crate::Context::handle`] 获取。
13pub fn spawn<F>(handle: &tokio::runtime::Handle, future: F) -> tokio::task::JoinHandle<F::Output>
14where
15    F: Future + Send + 'static,
16    F::Output: Send + 'static,
17{
18    handle.spawn(future)
19}
20
21/// 在 Iris 运行时句柄上阻塞执行一个异步任务。
22pub fn block_on<F>(handle: &tokio::runtime::Handle, future: F) -> F::Output
23where
24    F: Future,
25{
26    handle.block_on(future)
27}