Ember run loop guide


Is there a comprehensive guide to the run loop? While working on my own app, I discovered some of the runloop’s power and was able to speed up my app tremendously. However, I still feel much of my understanding is very partial and hacky. I wish in the main guides section, this can be better explained.

More specifically, one thing that still really confuses me is the following quote from the api guide:

If no run-loop is present, it creates a new one.

I am always under the impression there is only 1 runloop, and any time one calls any Ember.run and friends, the functions are scheduled back into the main runloop. But the above quote seems to imply there being multiple runloops? If not, does it mean the runloops may not be always actively looping?

Second thing I still find somewhat confusing is which queue is my code currently executing in? It would be nice to be able to query run object to help debugging, something like:

console.log Ember.run.executingInQueue()

I guess the reason this is confusing is even though Ember could be currently executing in say the render queue, some code can potentially force it back to sync or action queue, which comes before render. I find this hard to reason about (why wouldn’t Ember instead of going back to a previous queue, just schedule the functions in the sync or actions queue in the next tick?). And this is made even worse when I found out .observe triggers immediately rather than scheduled in one of the queues.

Anyway, aside from the confusions, I see how powerful this runloop concept is and am glad I pick ember over some other frameworks. But… if you got it, flaunt it. :smile:


Check out this thread by @rwjblue for info about the queues.