Julio Biason
1 year ago
4 changed files with 203 additions and 0 deletions
@ -0,0 +1,164 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "addr2line" |
||||||
|
version = "0.20.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" |
||||||
|
dependencies = [ |
||||||
|
"gimli", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "adler" |
||||||
|
version = "1.0.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "autocfg" |
||||||
|
version = "1.1.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "backtrace" |
||||||
|
version = "0.3.68" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" |
||||||
|
dependencies = [ |
||||||
|
"addr2line", |
||||||
|
"cc", |
||||||
|
"cfg-if", |
||||||
|
"libc", |
||||||
|
"miniz_oxide", |
||||||
|
"object", |
||||||
|
"rustc-demangle", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "cc" |
||||||
|
version = "1.0.79" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "cfg-if" |
||||||
|
version = "1.0.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "channeltest" |
||||||
|
version = "0.1.0" |
||||||
|
dependencies = [ |
||||||
|
"tokio", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "gimli" |
||||||
|
version = "0.27.3" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "libc" |
||||||
|
version = "0.2.147" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "memchr" |
||||||
|
version = "2.5.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "miniz_oxide" |
||||||
|
version = "0.7.1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" |
||||||
|
dependencies = [ |
||||||
|
"adler", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "object" |
||||||
|
version = "0.31.1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" |
||||||
|
dependencies = [ |
||||||
|
"memchr", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "pin-project-lite" |
||||||
|
version = "0.2.10" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "proc-macro2" |
||||||
|
version = "1.0.66" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" |
||||||
|
dependencies = [ |
||||||
|
"unicode-ident", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "quote" |
||||||
|
version = "1.0.31" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "rustc-demangle" |
||||||
|
version = "0.1.23" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "syn" |
||||||
|
version = "2.0.26" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"unicode-ident", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "tokio" |
||||||
|
version = "1.29.1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" |
||||||
|
dependencies = [ |
||||||
|
"autocfg", |
||||||
|
"backtrace", |
||||||
|
"pin-project-lite", |
||||||
|
"tokio-macros", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "tokio-macros" |
||||||
|
version = "2.1.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"syn", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "unicode-ident" |
||||||
|
version = "1.0.11" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" |
@ -0,0 +1,9 @@ |
|||||||
|
[package] |
||||||
|
name = "channeltest" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2021" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
tokio = { version = "1.29.1", features = ["sync", "macros", "rt", "time"] } |
@ -0,0 +1,3 @@ |
|||||||
|
# ChannelTest |
||||||
|
|
||||||
|
Testing how channels are kept or close when their task dies. |
@ -0,0 +1,27 @@ |
|||||||
|
use std::time::Duration; |
||||||
|
|
||||||
|
use tokio::{sync::mpsc, time::sleep, task}; |
||||||
|
|
||||||
|
#[tokio::main(flavor = "current_thread")] |
||||||
|
async fn main() { |
||||||
|
let (tx, mut rx) = mpsc::channel(10); |
||||||
|
|
||||||
|
let producer = task::spawn(async move { |
||||||
|
for i in 0..10 { |
||||||
|
println!("Produced {i}"); |
||||||
|
tx.send(i).await.expect("Failed to send data"); |
||||||
|
sleep(Duration::from_millis(i * 100)).await; |
||||||
|
} |
||||||
|
println!("=== Producer is done!") |
||||||
|
}); |
||||||
|
|
||||||
|
let consumer = task::spawn(async move { |
||||||
|
while let Some(i) = rx.recv().await { |
||||||
|
println!("Received {i}"); |
||||||
|
sleep(Duration::from_millis(i * 200)).await; |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
producer.await.expect("Producer died"); |
||||||
|
consumer.await.expect("Consumer died"); |
||||||
|
} |
Loading…
Reference in new issue