-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why I get const correctness problems #79
Comments
This won't compile as well agrpc::repeatedly_request(m_service,
asio::bind_executor(
m_grpc_context.get_executor(),
[p = this](agrpc::GenericRepeatedlyRequestContext<>&& ctx) mutable
{
asio::spawn(p->m_grpc_context, [](auto) { });
})
); |
By capturing
Solution is to move the lambda: auto f = [ctx = std::move(ctx)](asio::yield_context yield) // btw yield_context is essentially just a shared_ptr, you should consider taking it by const&
{
};
asio::spawn(m_grpc_context, std::move(f)); // std::move added here In more recent versions of asio you also need to provide a completion token to asio::spawn(m_grpc_context, std::move(f), asio::detached); Your example with repeatedly_request compiles fine for me but looks incomplete? Of course I assume that |
There must be something else, this code also won't compile agrpc::repeatedly_request(m_service,
asio::bind_executor(
m_grpc_context.get_executor(),
[this](agrpc::GenericRepeatedlyRequestContext<>&& ctx)
{
auto f = [](auto) { };
asio::spawn(m_grpc_context, std::move(f));
})
); |
Ok, can you show the surrounding member function and the declaration of the member variables |
agrpc::GrpcContext m_grpc_context;
grpc::AsyncGenericService m_service;
The member function on the other hand void run()
{
agrpc::repeatedly_request(m_service,
asio::bind_executor(
m_grpc_context.get_executor(),
[this](agrpc::GenericRepeatedlyRequestContext<>&& ctx)
{
...
});
})
);
} |
Thank you. You should remove the auto get_executor() const noexcept { return m_grpc_context.get_executor(); } |
I did try this to remove, both from this function and from the |
But how would your code work without const? |
Can you give me more context, for example more of the surrounding code? Also what version of asio are you using? |
Also more of the error message, I don't think it is just one line? |
Try this one: asio::spawn(m_grpc_context.get_executor(), std::move(f)); Looks like older versions of asio have issues identifying EDIT: Nevermind, not actually the case |
I ended up implementing with stackless coroutines. It less convenient but can make my code more general with |
The
|
Ok. But what about functions like |
On the server-side, gRPC does not provide detailed information on why a message couldn't be send to the client. They just give these possible reasons:
|
Great, thanks. |
Hi again, sorry for having to ask again but the time I have to incorporate this in our project is close to being exhaused and my previous experience with asio is not proving helpful here.
I have copied the piece of code below from the generic server into our code and I am getting
errors, regardless how I add or remove
const
in the functions. Here is the codeand elsewhere I call
agrpc::repeatedly_request(m_service, GenericRequestHandler{m_grpc_context});
Can you spot the problem? I would be grateful with any help.
The text was updated successfully, but these errors were encountered: