Skip to content

Instantly share code, notes, and snippets.

@zanbaldwin
Created December 28, 2023 13:10
Show Gist options
  • Save zanbaldwin/02e751a5070c2bcaf8260e9f321bd333 to your computer and use it in GitHub Desktop.
Save zanbaldwin/02e751a5070c2bcaf8260e9f321bd333 to your computer and use it in GitHub Desktop.
Why can't I understand async :(
pub fn function_from_external_crate<F, I>(get_more_info: F) -> Vec<Action>
where
F: FnMut(&str) -> I,
I: IntoIterator<Item = String>,
{
todo!()
}
async fn function_in_my_crate(conn: &Pool<Postgres>) { // <-- Currently inside an async function so
// can't create a runtime within a runtime?
let actions_to_take = function_from_external_crate(|id| {
sqlx::query("SELECT info FROM things WHERE something = $1")
.bind(id)
.fetch_all(conn)
.await // <-- How do I do this? We're currently within a sync clsure.
.into_iter()
.map(|row| row.get("info").to_string())
.collect::<Vec<_>>()
});
// Confuse == sad :(
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment