If a bunch of UIEvents are queued up because of some long-running method in a script, and at the end of the method I setTimeout(myfunc, 0), what order will myfunc get called in relative to handlers for the previously queued events? Is it guaranteed to be called after all previously queued events get handled?
setTimeout and UIEvent order
479 Views Asked by Andy At
2
There are 2 best solutions below
Related Questions in JAVASCRIPT
- Angular Show All When No Filter Is Supplied
- Why does a function show up as not defined
- I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
- Set "More" "Less" font size
- Using pagination on a table in AngularJS
- How to sort these using Javascript or Jquery Most effectively
- how to fill out the table with next values in array with one button
- State with different subviews
- Ajax jQuery firing multiple time display event for the same result
- Getting and passing MVC Model data to AngularJS controller
- Disable variable in eval
- javascript nested loops waiting for user input
- .hover() seems to overwrite .click()
- How to sort a multi-dimensional array by the second array in descending order?
- How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?
Related Questions in DOM-EVENTS
- How to get a button's ID when clicked in Windows 8 apps?
- Google maps API additional events
- How to bind event to appended element in jQuery
- Dynamically added event handler disables the previous one in JavaScript
- Plain JavaScript prevent eventListener being executed twice
- Why isn't my Google Tag Manager event listener being installed?
- Separate click event from focus event in Angular.js
- Create a custom event for a Polymer Custom-Element
- IndexedDB: Can you manually initiate a version change transaction?
- Namespace vanilla JavaScript events like in jQuery
- Trigger JavaScript action on click?
- Touch event doesn't alert latitude
- onended audio event firing without playing the audio
- What WheelEvent.deltaZ refers to?
- Basic Calculator - event binding using pure JavaScript
Related Questions in SETTIMEOUT
- jQuery: How to use setTimeout for temporary change of background color
- setTimeout inside iteration of iteration
- tricky setTimeout sequence
- Issues with resetting an interval
- A website I'm trying to use JavaScript on is replacing my setTimeout function with dots. Why might it be doing this, and how can I work around it?
- setTimeout with condition inside before running again
- Faster Sliding after a few hours of setTimeout
- Is it true that if possible I should never use setInterval & setTimeout?
- Javascript reruning timeout after being cleared
- setTimeout dont work on .hover() leave/stop
- JQuery - delay and show text issue
- Remove childElements one-by-one in pure JavaScript
- Timeout with bind, call & apply methods
- javascript increment setInteval counter while video is playing
- Resolving latency with setTimeout for Drum Machine
Related Questions in UIEVENT
- disable UIScrollView dragging event to specific direction and send the event to super
- uiview hierarchy and manage uievent
- Programmatically tap a view
- Get all current UITouches, including ones that aren't being updated
- iphone remoteevent notifications not getting called for MPMoviePlayer
- When overriding pressesBegan, etc., on iOS, how to handle multiple presses?
- Order of UIGestureRecognizer touchesBegan(_:with:) and point(inside:with:)
- Getting touches at launch on iOS
- Override addTarget method
- Button press events not getting called
- GPUImage does not update when MotionShake detected
- iOS - UIScrollView hitTest doesn't contain touches
- Generating Remote Control Events from my app
- Why can't the event be triggered when the iOS view moves
- How to type scroll event in React?
Related Questions in EVENTQUEUE
- How to prepend message to Javascript event queue? (Canceling long running methods)
- How to cancel Ajax queued up callbacks? (How to cancel long running method in Javascript?)
- Java EventQueue. When should I consider using it?
- console log inside a setTimeout unexpected delay
- NetBeans' HintsController and EventQueue
- How to share information between GUI threads?
- Get current instance of Runnable
- Why can't gdb read io_uring_cqe contents?
- Why do functions from event queue aren't called even when main executions stack is empty?
- SV assertion to flag incorrect verilog event region
- setTimeout and UIEvent order
- How to properly asychronously load UI component using Event Queues in ZK framework?
- Is update from EDT in swing an absolute rule or are there exceptions?
- why do i need EventQueue to start a new thread in java EDT? (JAVA)
- Java: how to use JTableModel in eventQueue
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Most events in the browser are processed in FIFO order (first in, first out) via a central event queue. Some UI events such as mousemove events are collapsed so you get the latest state, not necessarily all the in-between events.
So, the question is really when the mouse event gets into the JS event queue. I wasn't really sure how this worked so I built a couple test demos. What I found was that the answer depends. If a UI event is what is hogging the JS Thread, then it looks like the other UI events don't get into the queue in front of the timer, but if the UI event finishes and some other action (not on the UI) hogs the CPU, then the evnets are queued in proper FIFO order. So, it appears that "it depends" (in Chrome which is what I have tested so far).
I will post links to the demos in a second...
This demo shows that if the CPU hogging activity is not in response to a button click, then other button clicks that occur before the
setTimeout()is schedule to fire will get processed before thesetTimeout():But, this demo where the CPU hogging happens in the button click event handler itself shows the opposite. The clicks that happened before the
setTimeout()was scheduled to fire did not get processed before it.Now, I ran these both in Firefox and found that in both cases Firefox processes the events in FIFO order (in the order they actually happened). For the second demo above, this is different than Chrome.
Now, I ran these both in IE and found that IE always processes the
setTimeout()before the UI events - different than both Firefox and Chrome.So, these tests show three different results in three different browsers.
Summarizing Results:
For reference, here's the test case that hogs the CPU in the button click event handler:
And, here's the test case that hogs the CPU after the button client event handler has finished.