Skip to content

Instantly share code, notes, and snippets.

@abradley2
Created November 15, 2024 04:30
Show Gist options
  • Save abradley2/54b845d40215f6b478ba66f193c623d2 to your computer and use it in GitHub Desktop.
Save abradley2/54b845d40215f6b478ba66f193c623d2 to your computer and use it in GitHub Desktop.
Tokio Drift
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