Skip to main content

spawn

Function spawn 

Source
pub fn spawn<F, T>(future: F) -> JoinHandle<T>
where F: Future<Output = T> + Send + 'static, T: Send + 'static,
Expand description

Spawn a new async task 生成新的异步任务

§Panics / 恐慌

Panics if called outside of a runtime context. 如果在运行时上下文之外调用则恐慌。

§Example / 示例

use hiver_runtime::task::spawn;

async fn my_task() -> i32 {
    42
}

async fn main() {
    let handle = spawn(my_task());
    let result = handle.wait().await.unwrap();
    assert_eq!(result, 42);
}

Note: This is a simplified implementation for Phase 2. Full integration with the runtime scheduler will be added in Phase 3. 注意:这是第2阶段的简化实现。 与运行时调度器的完全集成将在第3阶段添加。