Comments (3)
The right pattern is pretty much the same -- you should be able to trace how all the asynchronous tasks join together back into your main thread.
If you're inside a task, this can be accomplished by returning the inner task you'd like to wait on. If you're simply in a normal c++ thread such as main(), you can call .get()
to "join" a task.
from cpprestsdk.
What does it mean in practice though? For example, what happens if we are in the middle of a network operation when we are exiting the application? Let's say we issued the request on an http_client object and the underlying network stack (and casablanca) is doing it's work, downloading a large file or waiting for a network timeout. How should we safely cancel such a task? In our app we have hundreds of these simultaneously (downloading avatars for people, tokens for decrypting contents etc). Should we keep track of all these request tasks? And if we have these tracked, how do we cancel them?
Thanks.
Gergely
from cpprestsdk.
When you create a request on an http_client
object, you can provide a const reference to a pplx::cancellation_token
object.
One way to utilize this is to create a pplx::cancellation_token_source
and pass that into the request via source.get_token()
.
On shutdown of your application you can then invoke a source.cancel()
method which will cancel the token provided to the request. If you have a continuation task on your long running operation (large file download, waiting for a network timeout), then you would need to catch exceptions within that task, i.e. pplx::task_canceled
.
from cpprestsdk.
Related Issues (20)
- Periodic drop in throughput in inter-(linux N/W namespace) communications HOT 1
- Static version of the nugget for Visual Studio Express 2013 for Windows Desktop
- The web_proxy doesn't work when set proxy with uri
- Charset support gbk...
- utility::details::str_iless(str1, str2);
- [MSVC] websocketsclient_test failed due to CHECK_EQUAL(ret_msg.length(), body_str.length()) where ret_msg.length()=32 and body_str.length()=5 HOT 1
- ../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found HOT 2
- async http client post/get request demo?
- nable to add both a file stream and key-value pairs to the body of the request simultaneously
- error: building cpprestsdk:x64-linux failed with: BUILD_FAILED HOT 3
- [http_client] CN checking against caller-specified Host header doesn't strip a port number
- using cpprest and segmentation fault on ubuntu 22.04 HOT 4
- hey dont worry about
- Need to double confirm if cpprestsdk supports HTTP proxy server secured by TLS
- vcpkg install should deploy ThirdPartyNotices.txt
- Build failed on Ubuntu HOT 2
- Running the example bingrequest.cpp resulted in a crash. HOT 2
- Build fails not finding openssl on GitHub MacOS runner
- 70+ Issues when building? HOT 1
- Nuget package does not have a build for ARM64 in the Window release. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpprestsdk.