Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 12, 2025 14:26
Show Gist options
  • Save rust-play/fcdc0211d50fe77f6bd9966a721c3f72 to your computer and use it in GitHub Desktop.
Save rust-play/fcdc0211d50fe77f6bd9966a721c3f72 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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