1#![cfg_attr(not(feature = "std"), no_std)]
10#![forbid(unsafe_code)]
11
12pub mod error;
13pub mod core;
14pub mod storage;
15pub mod executor;
16pub mod utils;
17
18pub use crate::error::{TaskError, Result};
19pub use crate::core::task::{Task, TaskStatus, TaskStore, TaskBody};
20pub use crate::storage::static_store::StaticStore;
21
22#[cfg(feature = "alloc")]
23pub use crate::storage::dynamic_store::DynamicStore;
24
25pub use crate::executor::sync::SyncExecutor;
26
27#[cfg(feature = "async")]
28pub use crate::executor::async_exec::AsyncExecutor;
29
30pub use crate::core::scheduler::validate_graph;
31pub use crate::core::events::{TaskEvent, TaskSubscriber};
32
33pub struct TaskGraph<S: TaskStore> {
35 storage: S,
36}
37
38impl<S: TaskStore> TaskGraph<S> {
39 pub fn new(storage: S) -> Self {
41 Self { storage }
42 }
43
44 pub fn task(&mut self, task: Task, deps: &[usize]) -> Result<usize> {
46 self.storage.add_task(task, deps)
47 }
48
49 pub fn run_sync(&mut self) -> Result<()> {
51 validate_graph(&mut self.storage)?;
52 let mut executor = SyncExecutor::new(&mut self.storage);
53 executor.run()
54 }
55
56 #[cfg(feature = "async")]
58 pub async fn run_async(self) -> Result<()>
59 where S: Send + Sync + 'static
60 {
61 let mut storage = self.storage;
62 validate_graph(&mut storage)?;
63 let executor = AsyncExecutor::new(storage);
64 executor.run().await
65 }
66}
67
68pub type StaticGraph<const N: usize> = TaskGraph<StaticStore<N>>;
70
71#[cfg(feature = "alloc")]
72pub type DynamicGraph = TaskGraph<DynamicStore>;