async-mqtt-client icon indicating copy to clipboard operation
async-mqtt-client copied to clipboard

[QUESTION] Use case for multiple callbacks

Open bertmelis opened this issue 5 years ago • 3 comments

All callbacks are stored in std::vectors. So multiple callbacks for the same events are possible. I have not had the need to attahc multiple callbacks however. And even then, if I only need a few actions I just use an intermediate function.

I know it is a breaking change, but just storing a std::function instead of a vector-of... would mean slightly faster code and less code. Don't know the effect on RAM.

What is the rationale?

bertmelis avatar Apr 30 '19 12:04 bertmelis

For me also multiple callbacks for the same event stored in vectors is overkill. I don't know if anyone uses multiple callbacks the for the same event. And indeed an intermediate function can perfectly solve this in a rare occasion when multiple callbacks are needed.

jeroenst avatar Nov 30 '19 22:11 jeroenst

Reviving this question.

A problem I have with the vector of callbacks is that it is not straightforward to remove a callback. Not a big problem, but still...

bertmelis avatar Jul 22 '21 14:07 bertmelis

I just started a project using multiple callbacks.

Usecase: different ESP32 use the same functions to publish state and handle OTA-Updater. Therefore on Callback is defined. The ESP32 specific task has its own callbacks and can be added separately.

tobiasjaster avatar May 29 '22 07:05 tobiasjaster