Interrupt a callback


I have written a plugin that generates syx messages from a machine learning model that is controlled by a set of sliders. The model takes about ~20ms each call on my machine and for this reason I want to give the user the option to either run the model in the process_block or in a listener callback. This way users with fast enough computers can have the model run in real time and users with slower computers can still make use of the plugin without it under-running.

Now when I have the model processing in the listener I get an issue where I slide a slider the callback gets called multiple times which means the model is being called multiple times simultaneously which causes lots of slowdowns.

I am wondering if there is a way to limit the maximum number of concurrent callbacks to just one and to have only the most recent callback to continue processing? Or if someone has a some other recommendation of a pattern that could bypass this issue?


If I understand your case correctly you can use for example Timer with a certain interval and check in its timerCallback() if your Slider was changed since the last check. If yes, you can call a needed function and then you are sure it is not called too often.

Yes, I think that is a good solution, thanks :slight_smile:

To save some CPU cycles, you can even start the Timer when the Slider value is changed (if it’s not already running) and stop it when you detect that there haven’t been changes to the Slider value.
This way, you save all the checks that would occur while the Slider is not touched by the user