Created
March 20, 2025 20:27
-
-
Save cgwalters/66d26237c7518f7ba279a4fcc2ded09e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
diff --git a/Cargo.toml b/Cargo.toml | |
index bd6165a..5bf6f9f 100644 | |
--- a/Cargo.toml | |
+++ b/Cargo.toml | |
@@ -19,7 +19,7 @@ serde = { features = ["derive"], version = "1.0.125" } | |
serde_json = "1.0.64" | |
semver = "1.0.4" | |
thiserror = "1" | |
-tokio = { features = ["fs", "io-util", "macros", "process", "rt", "sync"], version = "1" } | |
+tokio = { features = ["fs", "io-util", "macros", "process", "rt", "sync", "time"], version = "1" } | |
tracing = "0.1" | |
# We support versions 2, 3 and 4 | |
cap-std-ext = ">= 2.0, <= 4.0" | |
@@ -27,6 +27,7 @@ cap-std-ext = ">= 2.0, <= 4.0" | |
[dev-dependencies] | |
anyhow = "1.0" | |
bytes = "1.5" | |
+rand = "0.9" | |
clap = { version = "4.4", features = ["derive"] } | |
[lib] | |
diff --git a/examples/client.rs b/examples/client.rs | |
index ee5095a..a680e3d 100644 | |
--- a/examples/client.rs | |
+++ b/examples/client.rs | |
@@ -1,4 +1,4 @@ | |
-use std::io::Write; | |
+use std::{io::Write, time}; | |
use anyhow::Result; | |
use clap::Parser; | |
@@ -86,6 +86,11 @@ async fn get_blob(o: GetBlobOpts) -> Result<()> { | |
Ok(()) | |
} | |
+fn random_sleeper() -> tokio::time::Sleep { | |
+ let r = rand::random_range(0..500); | |
+ tokio::time::sleep(time::Duration::from_millis(r)) | |
+} | |
+ | |
async fn fetch_container_to_devnull(o: GetMetadataOpts) -> Result<()> { | |
let config = o.proxy_opts(); | |
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?; | |
@@ -95,6 +100,18 @@ async fn fetch_container_to_devnull(o: GetMetadataOpts) -> Result<()> { | |
let (mut blob, driver) = proxy.get_descriptor(img, layer).await?; | |
let mut devnull = tokio::io::sink(); | |
let copier = tokio::io::copy(&mut blob, &mut devnull); | |
+ let copier = async move { | |
+ random_sleeper().await; | |
+ let r = copier.await; | |
+ random_sleeper().await; | |
+ r | |
+ }; | |
+ let driver = async move { | |
+ random_sleeper().await; | |
+ let r = driver.await; | |
+ random_sleeper().await; | |
+ r | |
+ }; | |
let (copier, driver) = tokio::join!(copier, driver); | |
dbg!(&copier); | |
dbg!(&driver); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment