Giter Site home page Giter Site logo

Comments (4)

Tradias avatar Tradias commented on August 23, 2024

gRPC provides two ways of handling cancellation of RPCs:

  1. Set a deadline for the entire RPC. In that case, if the deadline is reached during the call to agrpc::finish the grpc::Status will be set to DEADLINE_EXCEEDED. The returned bool will still be true because the call actually made it to the server successfully, see also here.

  2. grpc::ClientContext::TryCancel(). If the cancellation was successful then apgrc::finish's grpc::Status will be set to CANCELLED. You could e.g. have a shorter deadline for an individual RPC step like so:

grpc::Alarm alarm;
agrpc::wait(alarm, std::chrono::system_clock::now() + std::chrono::seconds(1),
            boost::asio::bind_executor(grpc_context,
                                        [&](bool alarm_expired)
                                        {
                                            if (alarm_expired)
                                            {
                                                client_context.TryCancel();
                                            }
                                        }));
co_await agrpc::finish(*reader, response, status);
alarm.Cancel();

and I might be able to get this to work with the new awaitable operators at some point as well. Note that for those to work the grpc::ClientContext would need to be passed to agrpc::finish so that it can be cancelled which is not yet possible.

from asio-grpc.

rbresalier avatar rbresalier commented on August 23, 2024

Thanks @Tradias for your answer.

from asio-grpc.

rbresalier avatar rbresalier commented on August 23, 2024

@Tradias : Since you are going to update some of the examples based on issue #7 , perhaps you could give an example of setting a deadline timer for one of the rpc calls.

from asio-grpc.

Tradias avatar Tradias commented on August 23, 2024

I have added an example on how to cancel a RPC step. The example is based on a unary RPC which should rather be deadlined with grpc::ClientContext::set_deadline, but it can be applied to streaming RPC steps as well. I leave it as an exercise to you to do that :).

    grpc::ClientContext client_context;
    client_context.set_deadline(std::chrono::system_clock::now() + std::chrono::seconds(5));

from asio-grpc.

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.