3 ms·
If you want to .await multiple futures that can return an error you can use tokio::try_join, futures_utils::try_join_all, etc. For example: let ( db
by duped 3y ago
If you want to .await multiple futures that can return an error you can use tokio::try_join, futures_utils::try_join_all, etc. For example:
let (
db_eid_cache,
table_eid_cache,
job_eid_cache,
table_summaries_cache,
job_summaries_cache,
query_summaries_cache,
) = try_join!(
create_db_eid_cache(aws_clients.clone(), config),
create_table_eid_cache(aws_clients.clone(), config),
create_job_eid_cache(aws_clients.clone(), config),
create_table_summaries_cache(aws_clients.clone(), config),
create_job_summaries_cache(aws_clients.clone(), config),
create_query_summaries_cache(aws_clients.clone(), config),
)?;
The code dealing with your clients looks suspect. Why do you have a global with a .get method that is async and returns a reference? It should probably be sync. On top of that it probably shouldn't be a global variable. Pass it in as context to the handler.
I'm also suspicious of having this `AwsClients` struct and a bunch of free functions that take it by owner. Why aren't you adding an `impl` block with those as methods? And why are they taking ownership requiring the .clone`?
- datadeft 3y agoGreat questions. I guess because I never used any language that had the concept of ownership and I could not find any example how to handle these connections. I try to take your input and refactor the code based on your input. Thanks a million!