Skip to content

Instantly share code, notes, and snippets.

@cramertj
Forked from benbrittain/async_await_no_tls.rs
Last active July 26, 2019 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cramertj/de3f16afe33c47cc814f3929cbe33a7a to your computer and use it in GitHub Desktop.
Save cramertj/de3f16afe33c47cc814f3929cbe33a7a to your computer and use it in GitHub Desktop.
#![feature(async_await)]
pub async fn bar() -> u32{
5
}
pub async fn foo() -> u32{
let z = bar().await;
5 + z
}
// Sorta lowered code
pub async fn bar() -> ::std::future::from_generator(move || { 5 })
pub async fn foo() -> ::std::future::from_generator(move |mut cx| {
let z = {
let mut pinned = bar();
loop {
match F::poll((unsafe { <::std::pin::Pin>::new_unchecked(&mut pinned) }), cx)) {
::std::task::Poll::Ready(result) => break result ,
::std::task::Poll::Pending => { }
}
cx = yield ();
}
};
5 + z
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment