-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question on catch exception for async operations #402
Comments
auto async_task = blob4.upload_text_async(U("test new overwrite text"), condition4, options4, context4);
try {
async_task.get(); // block until the task is finished.
}
catch (const std::exception& e) {
std::cout << U("Error: ") << e.what() << std::endl;
} |
Thanks for your reply! Uhm, would that piece of code become sync upload then? |
The return type for Take cloud_blob::exists() for example, the sync version returns a |
In your sample code, yes. Because there's only one task. You can start a bunch of asynchronous tasks and then wait for them in one thread, like std::vector<pplx::task<T>> tasks;
tasks.emplace_back(an_async_function());
for (auto& t: tasks) {
t.get();
} Note that it's your responsibility to observe every potential exception in async task. So if you're pretty sure some async task won't throw, you don't have to call |
@sherlockwu BTW, this project has been deprecated in favor of our new version of storage SDK. So if you're starting a new project, you may want to try the new sdk. |
Thanks for your reply. Perhaps I could talk more about our expected behaviors. We'd like to
Now, I'm using .then() to implement the follow-up works. However, turns out we cannot know the uploads succeeded or not. Thanks for telling us about storage SDK. Would our need be easier to implement with azure-sdk? Thanks |
Every API has an overload which takes an In the auto t = blob4.upload_text_async(U("test new overwrite text"), condition4, options4, context4).then([](pplx::task<void> previous_task) {
try {
previous_task.get();
}
catch (azure::storage::storage_exception& e)
{
// failed, do clean up work here
}
// not failed, do other work
});
t.wait(); // This waits for the continuation task (defined by the lambda). |
The new SDK only supports synchronous API, which is much easier to use. Asynchronous task in this sdk is less easy to comprehend and is error-prune. In addition, although the API interface is asynchronous, it uses a thread-pool under the hood, so there's really no performance gain here. Actually our new SDK has much better performance than this old sdk. |
Got you. That sample code looks like what we indeed need. Thanks a lot for the help. |
Hi all,
I have a question related to catching exception for azure blob async upload operations.
Here is my sync version: (upload if not exist)
The catch part will catch the exception if the blob already exists.
My question is:
Thank you,
Kan
The text was updated successfully, but these errors were encountered: