What constitutes a run loop side effect?

Yep, that totally makes sense, and thank you for writing down your thought process (it really is helpful)!

As @ef4 mentioned, we are working to remove that auto-run assertion (hopefully by the time 3.3 or 3.4 rolls around we will have landed that). In the meantime, using async / await in application code is pretty annoying (largely because of the auto-run assertion).

For example:


// app/components/gist-edit.js
export default Component.extend({
  actions: {
    async update() {
      // using native `fetch` here (not ember-fetch)
      await fetch('https://api.github.com/gists', {
        method: 'post',
        body: JSON.stringify({ /* snip */ })
      })

      this.set('flash-alert', 'successfully updated!');
    }
  }
});

To walk this through:

  1. Ember automatically invokes the update action itself within a run-loop
  2. The fetch is kicked off
  3. When the fetch is finished the previously started run-loop is long gone
  4. The this.set('flash-alert' runs
  5. Setting any property that is rendered in the DOM, schedules a re-render
  6. :boom: auto-run assertion: cannot schedule when not within a run loop
  7. :sob: :cry: :crying_cat_face: :disappointed:
2 Likes