Closed sknagappan closed 1 year ago
Since you can use lambda or function object (class which overloads call operator) as callback, there's no need to have an extra parameter for the callback. Because you can set user context/data in lambda or function object.
UserData data;
sub.on_message([data](std::string channel, std::string msg) {
// Process message with user data: data
});
or
class Callback {
public:
Callback(UserData data) : _data(data) {}
void operator(std::string channel, std::string msg) {
// process message with user data: _data
}
private:
UserData _data;
};
sub.on_message(Callback(user_data));
Regards
Currenlty Subscriber::on_message() has callback interface "void (std::string channel, std::string msg)" it will be useful if it has an optional void param to hold some user context/data like "void (std::string channel, std::string msg, void user_data)"