Skip to main content

tinyflow_framework/runtime/
pending_task.rs

1//! Deferred task launch for chain execution (collect then spawn).
2
3/// Prepared task: call [`PendingTask::spawn`] to start on the runtime.
4pub struct PendingTask {
5    pub task_id: u32,
6    start: Box<dyn FnOnce() -> tokio::task::JoinHandle<()> + Send>,
7}
8
9impl PendingTask {
10    pub fn new<F>(task_id: u32, start: F) -> Self
11    where
12        F: FnOnce() -> tokio::task::JoinHandle<()> + Send + 'static,
13    {
14        Self {
15            task_id,
16            start: Box::new(start),
17        }
18    }
19
20    pub fn spawn(self) -> tokio::task::JoinHandle<()> {
21        (self.start)()
22    }
23}