[Laszlo-dev] Idle callbacks are the devil's tools!
Don Hopkins
dhopkins at DonHopkins.com
Tue Jun 7 17:15:12 PDT 2005
Am I doing this wrong, or is there a bug in LzIdle.callOnIdle?
When you run the following code (enclosed), the foobar method doesn't
get called.
The documentation for callOnIdle is worded strangely. It says:
LzIdle.callOnIdle(d)
Calls the given delegate at the next idle event. This can be used for a
non- recursive callback.
Shouldn't that be "non-repeating"? (I don't think "recursive" is the
right word to describe a repeating callback.) The documentation should
be explicit about the fact that the delegate is called only once, and
then unregistered. (And the behavior of the code should match the
documentation! ;-)
To work around this problem, I'm just registering an LzIdle.onidle
callback, and unregistering it when it happens. I want to defer some
layout processing until after all replication has happened. But
unfortunately the replication seems to be happening via onidle
processing too, so we're both waiting in the same line, and it calls my
lazy layout callback before all the replication is finished.
Is there a way to register a lower priority onidle callback that will
only run once all the pending replication and instantiation is finished?
I'd like for my idle callback to go to the end of the line each time
something changes.
If I unregister and reregister my onidle callback (instead of checking
to see if I'm already registered and not doing anything in that case,
keeping my place in line) will my delegate go to the end of the line
behind any pending replication callbacks? But that would require more
processing, so I'd prefer a lazier way to be lazy.
I am considering using a timer instead, but that would introduce an
unnecessary delay, and it still might fire too early.
It would be nice to have a reallyidle event that gets fired when the
idle queue is empty.
-Don
<canvas
width="100%" height="100%">
<attribute name="del" value="null"/>
<method event="oninit"><![CDATA[
this.del = new LzDelegate(this, 'foobar');
Debug.write("calling LzIdle.callOnIdle", this.del);
LzIdle.callOnIdle(this.del);
]]>
</method>
<method event="foobar" args="args"><![CDATA[
Debug.write("foobar should be called, but isn't...", args,
this.del);
]]>
</method>
</canvas>
More information about the Laszlo-dev
mailing list