From 81243574ec8ab3a27af6e8570ec6673d3f7af6ee Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 22 Nov 2024 13:59:50 +0800 Subject: [PATCH] fix examples & add ci for running examples (#19) --- .github/workflows/check-test.yaml | 5 +++++ examples/detach.rs | 6 +++--- examples/verbose.rs | 2 +- rust-toolchain | 2 +- src/registry.rs | 4 ++-- src/tests.rs | 2 -- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index 5392d98..8ffc044 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -22,6 +22,11 @@ jobs: run: cargo clippy --all-targets --all-features - name: Run tests run: cargo test + - name: Run examples + run: | + for example in $(ls examples/ | sed 's/\.rs$//'); do + cargo run --example $example + done semver: runs-on: ubuntu-latest diff --git a/examples/detach.rs b/examples/detach.rs index 3d01a42..1901850 100644 --- a/examples/detach.rs +++ b/examples/detach.rs @@ -53,7 +53,7 @@ async fn main() { tokio::spawn(root.instrument(work(rx))); sleep(Duration::from_millis(100)).await; - let tree = registry.get(&()).unwrap().to_string(); + let tree = registry.get(()).unwrap().to_string(); // work [106.290ms] // select [106.093ms] @@ -62,7 +62,7 @@ async fn main() { println!("{tree}"); sleep(Duration::from_secs(1)).await; - let tree = registry.get(&()).unwrap().to_string(); + let tree = registry.get(()).unwrap().to_string(); // work [1.112s] // rx [606.944ms] @@ -72,7 +72,7 @@ async fn main() { tx.send(()).unwrap(); sleep(Duration::from_secs(1)).await; - let tree = registry.get(&()).unwrap().to_string(); + let tree = registry.get(()).unwrap().to_string(); // work [2.117s] // fut [2.117s] diff --git a/examples/verbose.rs b/examples/verbose.rs index 6b6a785..b5c117f 100644 --- a/examples/verbose.rs +++ b/examples/verbose.rs @@ -32,7 +32,7 @@ async fn work(verbose: bool) -> String { tokio::spawn(root.instrument(foo())); sleep(Duration::from_secs(1)).await; - registry.get(&()).unwrap().to_string() + registry.get(()).unwrap().to_string() } #[tokio::main] diff --git a/rust-toolchain b/rust-toolchain index bc8a658..a92432a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.74 +1.82 diff --git a/src/registry.rs b/src/registry.rs index 6b68999..e103670 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -186,8 +186,8 @@ impl Registry { /// /// 1. If the current task is registered with a registry, returns the registry. /// 2. If the global registry is initialized with - /// [`init_global_registry`](crate::global::init_global_registry), returns the global - /// registry. + /// [`init_global_registry`](crate::global::init_global_registry), returns the global + /// registry. /// 3. Otherwise, returns `None`. pub fn try_current() -> Option { crate::root::current_registry() diff --git a/src/tests.rs b/src/tests.rs index c33fd17..db5b868 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -12,7 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(test)] - mod functionality; mod spawn;