MATLAB Object-Oriented Programming

(Joyce) #1

Callback Execution


In this section...
“When Callbacks Execute” on page 11-34
“Listener Order of Execution” on page 11-34
“Callbacks That Call notify” on page 11-34
“Manage Callback Errors” on page 11-35
“Invoke Functions from Function Handles” on page 11-35

When Callbacks Execute


Listeners execute their callback function when notified that the event has occurred.
Listeners are passive observers in the sense that errors in the execution of a listener
callback do not prevent the execution of other listeners responding to the same event, or
execution of the function that triggered the event.

Callback function execution continues until the function completes. If an error occurs in a
callback function, execution stops and control returns to the calling function. Then any
remaining listener callback functions execute.

Listener Order of Execution


The order in which listeners callback functions execute after the firing of an event is
undefined. However, all listener callbacks execute synchronously with the event firing.

The handle class handle.notify method calls all listeners before returning execution to
the function that called notify.

Callbacks That Call notify


Do not modify and reuse or copy and reuse the event data object that you pass to notify,
which is then passed to the listener callback.

Listener callbacks can call notify to trigger events, including the same event that
invoked the callback. When a function calls notify, MATLAB sets the property values of
the event data object that is passed to callback functions. To ensure that these properties

11 Events — Sending and Responding to Messages

Free download pdf