Clarification on Aynchronous programming #3692
-
|
Hi,
Assuming that I can grant that the
void put_async(const S3Client& client, const PutObjectRequest& request) {
...
s3Client.PutObjectAsync(
request,
[](const Aws::S3::S3Client*,
const Aws::S3::Model::PutObjectRequest&,
const Aws::S3::Model::PutObjectOutcome& outcome,
const std::shared_ptr<const Aws::Client::AsyncCallerContext>&)
{
//Callback logic here.
});
...
}Thank you in advance for any input! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi. Thanks for your question.
There are a couple things here:
Yes, It's primarily about resource handling.
As noted earlier, you can use
Lambdas are fine, the only thing to be careful about is captures (potential for lifetime issues). Consider the following example: |
Beta Was this translation helpful? Give feedback.
Hi. Thanks for your question.
There are a couple things here:
Aws::ShutdownAPI()during an async operation would likely result in the in-flight operations to return errors about client initialization - this will be a graceful exit. However, it's important to note thatAws::ShutdownAPI()will still wait for threads to finish completion in order to properly cleanup resources.