Reputation: 858
I have code that requests a stream of data from a grpc::Server with a grpc::ClientReader. The main loop looks like below, and runs in a seperate task. I need to shutdown task when destructor, but the Read() method is blocking. There doesn't seem to be anything I can do to mcReader to get it to stop blocking. I would rather not use deadline, because data isn't completely periodic, and making it big enough to do antyhign would still block a long time. What should I do?
while (mcReader->Read(&dataProductWrapper) && meTasksRunning)
{
// Do some work.
}
Upvotes: 4
Views: 4415
Reputation: 858
So looking around I figured it out. Using the grpc::ClientContext that gets passed into RPC call, you can call grpc::ClientContext::TryCancel() you can cancel from another thread.
Upvotes: 6