-
-
Save rust-play/fcdc0211d50fe77f6bd9966a721c3f72 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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::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