Can I run the async code inside non-async application? #713
Answered
by
Velfi
CaliViking
asked this question in
Q&A
-
|
I have a regular multi threaded application sync and I do not want to make the application async. |
Beta Was this translation helpful? Give feedback.
Answered by
Velfi
Jan 20, 2023
Replies: 2 comments 2 replies
-
|
The SDK is use aws_sdk_dynamodb::{Client, Error};
use tokio::runtime::Runtime;
fn make_a_request_with_the_sdk() -> Result<(), Error>> {
// Create the runtime
let rt = Runtime::new()?;
// Spawn the root task
rt.block_on(async {
let config = aws_config::load_from_env().await;
let client = Client::new(&config);
let resp = client.list_tables().send().await?;
println!("Tables:");
let names = resp.table_names().unwrap_or_default();
for name in names {
println!(" {}", name);
}
println!();
println!("Found {} tables", names.len());
})
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Velfi
-
|
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The SDK is
asyncand that won't change in the foreseeable future. However, running async code is as simple as creating atokioruntime: