Created
November 15, 2024 04:30
-
-
Save abradley2/54b845d40215f6b478ba66f193c623d2 to your computer and use it in GitHub Desktop.
Tokio Drift
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
use tokio::sync::mpsc; | |
#[tokio::main] | |
async fn main() { | |
let result = run(); | |
assert_eq!(result, 2); | |
} | |
fn run() -> u32 { | |
let (tx, mut rx) = mpsc::channel(32); | |
let tx2 = tx.clone(); | |
tokio::spawn(async move { | |
tx.send(()).await.unwrap(); | |
}); | |
tokio::spawn(async move { | |
tx2.send(()).await.unwrap(); | |
}); | |
let mut count = 0; | |
while count < 2 { | |
let _ = rx.blocking_recv(); | |
count += 1; | |
} | |
count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment