-
-
Save RandyMcMillan/10df5516bb8cbeb4833ca9c2f12694f8 to your computer and use it in GitHub Desktop.
tokio_oneshot.rs
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