How to implement Asynchronous chain request by grpc-rpc

A chained call to a grpc request needs to be implemented in the business. The service flow is as follows:

client- > serverA- > serverB

the code to create the CallData, on the grpc server is as follows:

class CallData {
    public:
        CallData(Save::AsyncService *service, ServerCompletionQueue *completionQueue) :
                status_(CREATE),
                service_(service),
                completionQueue_(completionQueue),
                responder_(&context_) {
            //Invoke the sereving logic right away
            Proceed();
        }

        void Proceed() {
            if (CREATE == status_) {
                status_ = PROCESS;
                service_->Request(&context_, &request_, &responder_, completionQueue_, completionQueue_, this);
            } else if (PROCESS == status_) {
                new CallData(service_, completionQueue_, sender_);
                
                //
                
                status_ = FINISH;
                responder_.Finish(reply_, Status::OK, this);
            } else {
                GPR_ASSERT(FINISH == status_);
                delete this;
            }
        }

    private:
        enum CallStatus {
            CREATE, PROCESS, FINISH
        };
        CallStatus status_;
        
        //
    };

Proceed in CallData did not think of how to proceed with the next asynchronous request and how to handle the returned result. Ask for advice!

Mar.04,2021

class CallData {

public:
    CallData(Save::AsyncService *service, ServerCompletionQueue *completionQueue) :
            status_(CREATE),
            service_(service),
            completionQueue_(completionQueue),
            responder_(&context_) {
        //Invoke the sereving logic right away
        Proceed();
    }

    void Proceed() {
        if (CREATE == status_) {
            status_ = PROCESS;
            service_->Request(&context_, &request_, &responder_, completionQueue_, completionQueue_, this);
            
            **doSomeThing();**
            
            
        } else if (PROCESS == status_) {
            new CallData(service_, completionQueue_, sender_);
            
            //
            
            status_ = FINISH;
            responder_.Finish(reply_, Status::OK, this);
        } else {
            GPR_ASSERT(FINISH == status_);
            delete this;
        }
    }

private:
    enum CallStatus {
        CREATE, PROCESS, FINISH
    };
    CallStatus status_;
    
    //
};
Menu