diff --git a/guides/release/applications/run-loop.md b/guides/release/applications/run-loop.md index e424dae961..8b039473e0 100644 --- a/guides/release/applications/run-loop.md +++ b/guides/release/applications/run-loop.md @@ -169,13 +169,15 @@ which will make you a better Ember developer. You should begin a run loop when the callback fires. -The `Ember.run` method can be used to create a run loop. -In this example, `Ember.run` is used to handle an online +The `run` method from `@ember/runloop` can be used to create a run loop. +In this example, `run` is used to handle an online event (browser gains internet access) and run some Ember code. ```javascript +import { run } from '@ember/runloop'; + window.addEventListener('online', () => { - Ember.run(() => { // begin loop + run(() => { // begin loop // Code that results in jobs being scheduled goes here }); // end loop, jobs are flushed and executed }); @@ -185,15 +187,17 @@ window.addEventListener('online', () => { ## What happens if I forget to start a run loop in an async handler? -As mentioned above, you should wrap any non-Ember async callbacks in `Ember.run`. +As mentioned above, you should wrap any non-Ember async callbacks in `run`. If you don't, Ember will try to approximate a beginning and end for you. Consider the following callback: ```javascript +import { schedule } from '@ember/runloop'; + window.addEventListener('online', () => { console.log('Doing things...'); - Ember.run.schedule('actions', () => { + schedule('actions', () => { // Do more things }); }); @@ -207,26 +211,28 @@ These automatically created run loops we call _autoruns_. Here is some pseudocode to describe what happens using the example above: ```javascript +import { begin, end, schedule } from '@ember/runloop'; + window.addEventListener('online', () => { // 1. autoruns do not change the execution of arbitrary code in a callback. // This code is still run when this callback is executed and will not be // scheduled on an autorun. console.log('Doing things...'); - Ember.run.schedule('actions', () => { + schedule('actions', () => { // 2. schedule notices that there is no currently available run loop so it // creates one. It schedules it to close and flush queues on the next // turn of the JS event loop. if (! Ember.run.hasOpenRunLoop()) { - Ember.run.begin(); + begin(); nextTick(() => { - Ember.run.end() + end() }, 0); } // 3. There is now a run loop available so schedule adds its item to the // given queue - Ember.run.schedule('actions', () => { + schedule('actions', () => { // Do more things }); @@ -234,7 +240,7 @@ window.addEventListener('online', () => { // 4. This schedule sees the autorun created by schedule above as an available // run loop and adds its item to the given queue. - Ember.run.schedule('afterRender', () => { + schedule('afterRender', () => { // Do yet more things }); }); @@ -242,5 +248,5 @@ window.addEventListener('online', () => { ## Where can I find more information? -Check out the [Ember.run](https://api.emberjs.com/ember/release/classes/@ember%2Frunloop) API documentation, +Check out the [@ember/runloop](https://api.emberjs.com/ember/release/classes/@ember%2Frunloop) API documentation, as well as the [Backburner library](https://github.com/ebryn/backburner.js/) that powers the run loop.