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
480 Views Asked by Andy At
2
There are 2 best solutions below
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in DOM-EVENTS
- How to listen for LightDOM Label "FOR=" events via ShadowDOM Custom Element
- Removing the beforeunload event does not work in React
- event handling for overlapping polygons in google maps
- EventListener is not being added to button elements
- Why is the blur event listener fired twice for the same element with contenteditable in this case?
- Popover API: Event bubbling not working on beforetoggle event?
- An HTML Link Element ("a") Refuses to Attach Itself to Event Listener
- "contextmenu" Event interrupts "onmousemove" from executing a function
- handling the cancel of window.onbeforeunload prompt
- How to appendchild() using drag drop with 2 hierarchically equal divs? using Typescript
- ResizeObserver callback is not being fired when rotated device two times
- How to append an element to a specific div - Vanilla JS?
- How to make every subsequent sibling after a button-wrapper disappear and restore their visibility again by pressing this very button?
- brush overlaps events on other elements
- Rotating chevron in accordion in javascript
Related Questions in SETTIMEOUT
- why throw inside of an setTimeout, located inside a promise, doesn't change state and result of the output promise?
- IF Else statement not properly worked in setInterval() function while creating count-down timer
- react useEffect cleanup function
- How to use setTimeout for removing items from cart
- how seTimeout() executing continuously?
- What should be the result and why?
- Why setTimeout is not working in nodejs server?
- Inconsistent Execution Order of setImmediate and setTimeout(0) in Node.js
- undefined parameter in JavaScript
- Details regarding micro-task queue checkpoints in Javascript
- Does Jest automatically restores the real timers after each test case?
- JavaScript - What is the difference between let and var in a for loop?
- useState re-renders the component(on a button click). I need to change the background of the component to red for 1 second before this happens
- How do I get my input to be displayed all at once instead of one by one
- How to handle setTimeout() for a list of items?
Related Questions in UIEVENT
- How to detect the location of a mouseDown event for a iOS App using Swift?
- How to type scroll event in React?
- How to change and apply the responder?
- Order of UIGestureRecognizer touchesBegan(_:with:) and point(inside:with:)
- When overriding pressesBegan, etc., on iOS, how to handle multiple presses?
- How to change the index of UISegmentControl (slide) dynamically without touching segments in Swift?
- UIView pass through touches only if more than one finger?
- Why can't the event be triggered when the iOS view moves
- Swift: Haptic effects for grid of UIButtons
- Tracking All Events of ViewController and UIControls for Custom Analytics Framework iOS
- iOS Responder Chain and Events
- Make sibling view ignore any touch input, the other sibling view should receive it
- iOS: How to implement the mask view event penetrate?
- How can I copy an UIEvent object to a local data structure?
- When do "finger" events get sent as Gestures to UIGestureRecognizer vs touchesBegan/touchesMoved/touchesEnded to UIView
Related Questions in EVENTQUEUE
- Why don't jobs in a Celery chain pass their result to next job when wrapped in a chord?
- Is there a way to know the functioning of the event queue in pygame?
- The execution order of setTimeout and AJAX onload callback function
- JavaScript onMouseDown and onClick events versus event queue
- Sending remainder email dynamically node js
- SV assertion to flag incorrect verilog event region
- Why can't gdb read io_uring_cqe contents?
- Avoiding Race Condition with event queue in event driven embedded system
- How Does the JavaScript Interpreter add Global Statements to the Event Queue?
- console log inside a setTimeout unexpected delay
- Why do functions from event queue aren't called even when main executions stack is empty?
- Java Swing Components Init NullPointerException
- How to create queue of events in order by date
- Event queue cleanup
- How to return a custom type <Hero> from View (GUI) to controller?
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 # Hahtags
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.