Background Info
I recently saw a tweet asking the same question that I had when I started diving in:
Where can I find a complete list of Ember RunLoop queues and their descriptions?
I have wondered the same thing so I took some time to track down as much of the details as I could. I have tried to indicate where I obtained the information about each queue (in case I am incorrect).
Ember Run Loop
The run loop is managed by an external micro-library named backburner.js (ebryn/backburner.js) which handles most (possibly all) of the actual queueing and scheduling of the run loop. This micro-lib is not Ember specific (although it was written with Ember in mind), and can be used from Backbone or even a standalone JS app.
Ember starts off by configuring Backburner with three queues (sync
, actions
, destroy
) which are setup here, two additional queues (render
and afterRender
) are added by the ember-views
package here, and finally the ember-routing
package also adds routerTransitions
here.
Listing Available Queues and their Order
You can see the list of run loop queues in your application along with their ordering by running Ember.run.queues
in the console:
Ember.run.queues
["sync", "actions", "routerTransitions", "render", "afterRender", "destroy"]
Queue Breakdown
-
sync
- Bindings use this queue so this method is a useful way to immediately force all bindings in the application to sync. Use this queue anytime you need any changed state to propagate throughout the app immediately without repainting the UI (which happens in the later ‘render’ queue added by theember-views
package). (See here for details.) -
actions
- This is the default queue and is used the most throughout the Ember codebase.- Used for
Ember.run
andEmber.run.later
by default. - RSVP promises resolve in this queue.
- Used for
-
routerTransitions
- Used in router transitions to prevent unnecessary loading state if all promises resolve on theactions
queue first. (See here.) -
render
- Used for rendering views after bindings have synced. All DOM element operations happen in this queue. -
afterRender
- Used for scheduling actions that occur after all view rendering (DOM operations) has occurred. -
destroy
- Used byEmber.Core.Object
within thedestroy
function (see here) to schedule destruction to happen at the end of the run loop.