Anyone listening for a particular event?
Show older comments
Hi,
I have an object that can fire many events, and computing the events takes a significant amount of time. Therefore, I would like to compute the events only if I know there is someone listening for them.
Is there any way for the object to get notified when a listener is added or removed? Is there any way to get the list of current listeners? Is there any way to check the count of active listeners for a given event?
Thanks, Joan
Accepted Answer
More Answers (2)
Andrew Newell
on 20 Mar 2011
I would think that the easiest way would be to define an event property in for each event, like this:
classdef complicatedClass < handle
...
events
event1
...
eventN
end
methods
function obj = longEvent1(obj,varargin)
...
notify(obj,'event1');
end
...
end
and then have a listener class, e.g., respondToEvent1, for each event. Then start them all at once and you can be sure something is listening without a lot of bookkeeping.
Joan Puig
on 20 Mar 2011
0 votes
Categories
Find more on Argument Definitions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!