Question
I have two listeners for event but according to documentation, "the order in which listeners execute is not defined". I want to check whether one callback has executed before the next without having that callback generate it's own event. Is there a way of doing this? For example: event: PayDay listener callbacks: UpdateBankAccount, GoShopping How can I ensure that UpdateBankAccount has ocurred before GoShopping?
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 22, 2026
If you implement the event provider yourself, it is possible to track which event listeners were fired before a specific callback.
You can implement a daughter class of event.EventData (I called it TrackableEventData here)
then you can add functionality for callbacks to subscribe once they are finished so that subsequent callbacks can check wheter a specific callback was fired already.
I made a class with the event PayDay (PayDayClass) this class will raise the PayDay event and send a copy of TrackableEventData in stead of the usual event.EventData that is generated by default (when you don't send anything particular).
The last class has both callbacks - UpdateBankAccount and GoShopping (I assume you have different classes for those callbacks but it doesn't matter for the sake of the example)
when the callbacks happen in the expected order, everything is fine, but when the order is wrong, an exception is thrown by the GoShopping callback.
A sidenote:
when making the example, I noticed that the event listeners always fired in LIFO order. As far as I can say, this behavior is not documented. Therefore, it may change between Matlab releases. Allthough, it could be just because it's almost impossible to track the order of registration of listeners in more complex use cases. Either way, I would'nt rely on this.
As far as I know, it is impossible to control the order of callbacks by any other means. So, If you want to control the order of callbacks, rather than just track which ones had already fired, you will have to implement your own event listeners. While it is possible, it is by far more complex.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related addlistener Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →