Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
custom:javascript:callbacks [2021/04/04 20:47] – [The Event Loop] Add note about how/why only one polled callback will get used Deuce | custom:javascript:callbacks [2021/04/05 12:49] (current) – [Callback API] Deuce | ||
---|---|---|---|
Line 9: | Line 9: | ||
**polled callbacks**\\ | **polled callbacks**\\ | ||
- | polled callbacks are those that will be called | + | polled callbacks are those that will be invoked |
**timer callbacks**\\ timer callbacks are invoked after a defined period of time. | **timer callbacks**\\ timer callbacks are invoked after a defined period of time. | ||
Line 36: | Line 36: | ||
'' | '' | ||
- | Installs a callback for the string '' | + | Installs a user callback for the string '' |
'' | '' | ||
- | Adds all callbacks which were installed with the specified '' | + | Adds all user callbacks which were installed with the specified '' |
'' | '' | ||
Line 90: | Line 90: | ||
The event loops is ran after the script finishes executing while js.do_callbacks is set and there are either timer or polled callbacks installed, or there are any items in the run queue. | The event loops is ran after the script finishes executing while js.do_callbacks is set and there are either timer or polled callbacks installed, or there are any items in the run queue. | ||
- | Note that since polled callbacks are triggered based on current state, only one will be triggered for each such state. | + | Note that since polled callbacks are triggered based on current state, only one will be triggered for each such state. |
Basically: | Basically: | ||
<code javascript> | <code javascript> | ||
while (js.do_callbacks && (timer_callback_count > 0 || polled_callback_count > 0 || run_queue.length > 0)) { | while (js.do_callbacks && (timer_callback_count > 0 || polled_callback_count > 0 || run_queue.length > 0)) { | ||
- | if (polled_callback_ready) { | + | |
+ | | ||
+ | timeout = 0; | ||
+ | poll_result = poll_callback_states(timeout); | ||
+ | if (poll_result.polled_callback_ready) { | ||
polled_callback.call(thisObj); | polled_callback.call(thisObj); | ||
continue; | continue; | ||
} | } | ||
- | if (timed_callback_ready) { | + | if (poll_result.timed_callback_ready) { |
timed_callback.call(thisObj); | timed_callback.call(thisObj); | ||
continue; | continue; | ||
} | } | ||
- | if (run_queue.length > 0) { | + | if (poll_result.run_queue.length > 0) { |
run_queue.shift().call(thisObj); | run_queue.shift().call(thisObj); | ||
continue; | continue; |