Code Monkey home page Code Monkey logo

Comments (3)

ras0219-msft avatar ras0219-msft commented on May 22, 2024

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.

glukacsy avatar glukacsy commented on May 22, 2024

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.

megaposer avatar megaposer commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.