Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active July 12, 2025 14:28
Show Gist options
  • Save RandyMcMillan/10df5516bb8cbeb4833ca9c2f12694f8 to your computer and use it in GitHub Desktop.
Save RandyMcMillan/10df5516bb8cbeb4833ca9c2f12694f8 to your computer and use it in GitHub Desktop.
tokio_oneshot.rs
use tokio::sync::oneshot;
async fn some_computation() -> String {
"represents the result of the computation".to_string()
}
#[tokio::main]
async fn main() {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
let res = some_computation().await;
tx.send(res).unwrap();
});
// Do other work while the computation is happening in the background
// Wait for the computation result
let res = rx.await.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment