From 182c2737cd6b8e9cf6761218dd19de54251ecc47 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 19:47:30 -0400 Subject: [PATCH] Add futures. --- Cargo.toml | 3 ++- src/bin_foreign_document_test.rs | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d83e92..1cfd314 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ path = "src/lib.rs" required-features = ["foreign_document_test"] [dependencies] +futures = { version = "0.3.28", optional = true } nom = "7.1.1" opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] } opentelemetry-otlp = { version = "0.13.0", optional = true } @@ -53,7 +54,7 @@ walkdir = "2.3.3" [features] default = ["compare", "foreign_document_test"] compare = [] -foreign_document_test = ["compare", "dep:tokio"] +foreign_document_test = ["compare", "dep:tokio", "dep:futures"] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] # Optimized build for any sort of release. diff --git a/src/bin_foreign_document_test.rs b/src/bin_foreign_document_test.rs index 44e76ba..ae5d276 100644 --- a/src/bin_foreign_document_test.rs +++ b/src/bin_foreign_document_test.rs @@ -4,6 +4,9 @@ use std::io::Read; use std::path::Path; use std::path::PathBuf; +use futures::future::BoxFuture; +use futures::future::FutureExt; +use futures::stream::FuturesUnordered; use organic::compare::run_anonymous_compare; use organic::compare::run_compare_on_file; @@ -41,8 +44,9 @@ async fn main_body() -> Result<(), Box> { let single_file = TestConfig::SingleFile(SingleFile { file_path: PathBuf::from("/tmp/test.org"), }); + let mut futs = FuturesUnordered::new(); // let result = single_file.run_test().await; - let result = tokio::spawn(single_file.run_test()); + let result = tokio::spawn(single_file.run_test()).await; println!("{:?}", result); // let test_config = TestConfig::TestLayer(TestLayer { // name: "foo", @@ -95,11 +99,14 @@ pub(crate) enum TestStatus { } impl TestConfig { - async fn run_test(self) -> TestResult { - match self { - TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await), - TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await), + fn run_test(self) -> BoxFuture<'static, TestResult> { + async move { + match self { + TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await), + TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await), + } } + .boxed() } }