From cbb8f43ad325c4f5a0e86e80865f71e817fc8536 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 19 Mar 2022 23:45:47 +0800 Subject: [PATCH] feat: add README.md --- __concurrent/async_study/README.md | 22 +++++++++++++++++++++ __concurrent/async_study/examples/async4.rs | 10 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 __concurrent/async_study/README.md create mode 100644 __concurrent/async_study/examples/async4.rs diff --git a/__concurrent/async_study/README.md b/__concurrent/async_study/README.md new file mode 100644 index 0000000..235bbba --- /dev/null +++ b/__concurrent/async_study/README.md @@ -0,0 +1,22 @@ +Import `tokio`: + +``` +tokio = { version = "1.0", features = ["full"] } +``` + +Usage: + +```rust +#[tokio::main] +async fn main() { + // TODO ... +} +``` + +`tokio` 提供以下几种 channels 类型: + +* mpsc: 多生产者,单消费者 - https://docs.rs/tokio/1/tokio/sync/mpsc/index.html +* oneshot: 单生产者,单消费者 - https://docs.rs/tokio/1/tokio/sync/oneshot/index.html +* broadcast: 多生产者,多消费者 - https://docs.rs/tokio/1/tokio/sync/broadcast/index.html +* watch: 单生产者,多消费者 - https://docs.rs/tokio/1/tokio/sync/watch/index.html + diff --git a/__concurrent/async_study/examples/async4.rs b/__concurrent/async_study/examples/async4.rs new file mode 100644 index 0000000..ca71a84 --- /dev/null +++ b/__concurrent/async_study/examples/async4.rs @@ -0,0 +1,10 @@ +fn main() { + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(async { + invoke().await + }); +} + +async fn invoke() { + println!("Hello World!"); +} \ No newline at end of file