Depend on futures-util instead of futures
This commit is contained in:
1 parent
f342e33f16
commit
a75defa5a6
79 files changed
+447
-380
No files matched your search
@@ -31,7 +31,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
// Step 1: Define a source task (no dependencies)
|
||||
//
|
||||
@@ -106,7 +106,7 @@ async fn main() {
|
||||
// 1. Tasks with no dependencies run first (x and y in parallel)
|
||||
// 2. Once x and y complete, sum runs (it depends on both)
|
||||
println!("Running DAG...\n");
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner, TaskHandle};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
// Source task with a value field
|
||||
struct Source {
|
||||
@@ -141,7 +141,7 @@ async fn main() {
|
||||
|
||||
// Run the DAG
|
||||
println!("Running fan-out DAG...\n");
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
struct FetchName;
|
||||
|
||||
@@ -134,7 +134,7 @@ async fn main() {
|
||||
|
||||
// Run the DAG
|
||||
println!("Running fan-in DAG...\n");
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagResult, DagRunner, Task, TaskInput};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::time::sleep;
|
||||
|
||||
@@ -125,7 +125,7 @@ async fn main() -> DagResult<()> {
|
||||
|
||||
let total = dag.add_task(Aggregate).depends_on((sum1, sum2, sum3, sum4));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() }).await?;
|
||||
|
||||
let result = dag.get(total)?;
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use tokio::sync::Mutex;
|
||||
@@ -390,7 +390,7 @@ async fn main() {
|
||||
false, // success
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -404,7 +404,7 @@ async fn main() {
|
||||
true, // fail
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -418,7 +418,7 @@ async fn main() {
|
||||
true, // fail
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -432,7 +432,7 @@ async fn main() {
|
||||
true, // fail
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -450,7 +450,7 @@ async fn main() {
|
||||
.add_task(FallbackService::new("ServiceCall-5"))
|
||||
.depends_on(call5);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -469,7 +469,7 @@ async fn main() {
|
||||
false, // success
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -483,7 +483,7 @@ async fn main() {
|
||||
false, // success
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagResult, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
// Extract: Load data from different sources
|
||||
struct LoadData {
|
||||
@@ -202,7 +202,7 @@ async fn main() -> DagResult<()> {
|
||||
|
||||
// Execute the entire ETL pipeline
|
||||
println!("Executing pipeline...\n");
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() }).await?;
|
||||
|
||||
// Display final report
|
||||
println!("\n{}", dag.get(report)?);
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagResult, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
// Task that validates and processes input
|
||||
struct ValidateAndDouble {
|
||||
@@ -138,7 +138,7 @@ async fn main() -> DagResult<()> {
|
||||
.depends_on((&cat1, &cat2, &cat3));
|
||||
|
||||
// Execute
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() }).await?;
|
||||
|
||||
// Display results
|
||||
println!("\nFinal summary: {}", dag.get(summary)?);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner, TaskHandle};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
struct User {
|
||||
@@ -107,7 +107,7 @@ async fn main() {
|
||||
let validation = dag.add_task(ValidateUser).depends_on(user_task);
|
||||
|
||||
// Execute the DAG
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
// Data source tasks
|
||||
struct LoadValue1;
|
||||
@@ -221,7 +221,7 @@ async fn main() {
|
||||
|
||||
// Execute the pipeline
|
||||
println!("Executing pipeline...\n");
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::time::Instant;
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
||||
@@ -401,7 +401,7 @@ async fn main() {
|
||||
.depends_on((inventory, payment, shipping));
|
||||
|
||||
// Run the DAG
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -441,7 +441,7 @@ async fn main() {
|
||||
true, // will fail
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
|
||||
// Source task that provides a string input
|
||||
struct StringSource(&'static str);
|
||||
@@ -223,7 +223,7 @@ async fn main() {
|
||||
let processed = dag.add_task(ProcessData).depends_on(validated);
|
||||
let logged = dag.add_task(LogError).depends_on(processed);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -249,7 +249,7 @@ async fn main() {
|
||||
let processed = dag.add_task(ProcessData).depends_on(validated);
|
||||
let logged = dag.add_task(LogError).depends_on(processed);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -275,7 +275,7 @@ async fn main() {
|
||||
let processed = dag.add_task(ProcessData).depends_on(validated);
|
||||
let logged = dag.add_task(LogError).depends_on(processed);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -298,7 +298,7 @@ async fn main() {
|
||||
.add_task(WithFallback { fallback: 0 })
|
||||
.depends_on(parsed);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
// Simple computation task
|
||||
@@ -182,7 +182,7 @@ async fn main() {
|
||||
println!(" Build time: {:?}", build_time);
|
||||
|
||||
let exec_start = Instant::now();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
let exec_time = exec_start.elapsed();
|
||||
@@ -222,7 +222,7 @@ async fn main() {
|
||||
println!(" Build time: {:?}", build_time);
|
||||
|
||||
let exec_start = Instant::now();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
let exec_time = exec_start.elapsed();
|
||||
@@ -273,7 +273,7 @@ async fn main() {
|
||||
println!(" Tree depth: {}", level);
|
||||
|
||||
let exec_start = Instant::now();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
let exec_time = exec_start.elapsed();
|
||||
@@ -331,7 +331,7 @@ async fn main() {
|
||||
println!(" Build time: {:?}", build_time);
|
||||
|
||||
let exec_start = Instant::now();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
let exec_time = exec_start.elapsed();
|
||||
@@ -355,7 +355,7 @@ async fn main() {
|
||||
.map(|i| dag.add_task(FormatNumber { id: i }))
|
||||
.collect();
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
||||
// Retry strategy configuration
|
||||
@@ -356,7 +356,7 @@ async fn main() {
|
||||
],
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -378,7 +378,7 @@ async fn main() {
|
||||
],
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -404,7 +404,7 @@ async fn main() {
|
||||
],
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -423,7 +423,7 @@ async fn main() {
|
||||
vec![ApiError::AuthenticationFailed],
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -450,7 +450,7 @@ async fn main() {
|
||||
],
|
||||
));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
+7
-7
@@ -24,7 +24,7 @@
|
||||
//!
|
||||
//! **2. DAG-Level Timeout** - Entire workflow with timeout
|
||||
//! ```rust
|
||||
//! match timeout(dag_timeout, dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await {
|
||||
//! match timeout(dag_timeout, dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() }).await {
|
||||
//! Ok(result) => { /* DAG completed */ },
|
||||
//! Err(_) => { /* DAG timed out */ },
|
||||
//! }
|
||||
@@ -99,7 +99,7 @@
|
||||
//! ```
|
||||
|
||||
use dagx::{task, DagRunner, TaskHandle};
|
||||
use futures::FutureExt;
|
||||
|
||||
use tokio::time::{sleep, timeout, Duration};
|
||||
|
||||
// Fast task that completes quickly
|
||||
@@ -178,7 +178,7 @@ async fn main() {
|
||||
timeout_ms: 500,
|
||||
});
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -198,7 +198,7 @@ async fn main() {
|
||||
|
||||
let processed = dag.add_task(ProcessResult).depends_on(timed);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -225,7 +225,7 @@ async fn main() {
|
||||
timeout_ms: 200,
|
||||
});
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -251,7 +251,7 @@ async fn main() {
|
||||
let processed1 = dag.add_task(ProcessResult).depends_on(source);
|
||||
let processed2 = dag.add_task(ProcessResult).depends_on(source);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -272,7 +272,7 @@ async fn main() {
|
||||
let dag_timeout = Duration::from_millis(500);
|
||||
match timeout(
|
||||
dag_timeout,
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)),
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() }),
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
//!
|
||||
|
||||
use dagx::{task, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
use tracing_subscriber::{fmt, EnvFilter};
|
||||
|
||||
// Simple source task
|
||||
@@ -96,7 +96,7 @@ async fn main() {
|
||||
// Layer 2: Combine results
|
||||
let result = dag.add_task(Add).depends_on((&left, &right));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -117,7 +117,7 @@ async fn main() {
|
||||
let c = dag.add_task(Multiply).depends_on((&b, &b));
|
||||
let d = dag.add_task(Add).depends_on((&c, &c));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -146,7 +146,7 @@ async fn main() {
|
||||
let sum_all = dag.add_task(Add).depends_on((&sum12, &sum23));
|
||||
let final_result = dag.add_task(Add).depends_on((&sum_all, &sum34));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in new issue
Block a user