Closed leiless closed 1 year ago
I never considered this. Is there a real use case to pass functions between threads?
I have a single socket fd, in which all the messages (request and response) should be done sequentially. So I want some callback to be passed to sequentia-lize between those messages.
Concurrent requests will cause the response to be out of order (byte streams).
Understood. It will take me a while to find time for this. Please leave the issue open.
If it's urgent for you, I can only suggest to use a class in the channel (with dynamic polymorphism or std::variant) if it's suitable for you.
This is because you try to push a lambda into a channel with type std::function<void()>
. But the lambda does not have that type; it has a unique type.
You can assign a lambda to a std::function object.
using function_type = std::function<void()>;
msd::channel<function_type> channel;
const function_type func = []() {};
channel << func;
function_type out;
channel >> out;
out();
Does this help you?
@leiless, have you tested this?
When you test again, please come back if the proposed solution does not work.
It seems that
msd::channel
does not support function pointer.