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:
- Ember automatically invokes the
update
action itself within a run-loop - The
fetch
is kicked off - When the
fetch
is finished the previously started run-loop is long gone - The
this.set('flash-alert'
runs - Setting any property that is rendered in the DOM, schedules a re-render
-
auto-run assertion: cannot schedule when not within a run loop
-