Refactor settled to avoid triggering a new run-loop. #263
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The code that was added to ensure that all
promise.then
orpromise.catch
callbacks are "flushed" before decrementing the counter (which fixed a number of bugs wheresettled
would accidentally becometrue
before the promise callbacks themselves could have a chance to run), caused an issue when using the legacymoduleForComponent
system to render a template that itself kicked off an async request.Prior to the changes made in this commit, when rendering would kick off async (e.g. rendering a
{{parent.child}}
style path referencing an ember-data async relationship) there would already be an existingEmber.run.backburner.currentInstance
(which was created by theRSVP.Promise.resolve().then(...)
being removed in this commit) which ultimately forced us down the path that meantadapter.asyncStart()
/adapter.asyncEnd()
would not be called (see here).This change works around that (admittedly niche) scenario by always assuming that a
Promise.resolve()
will execute before the nextsetTimeout(cb, 0)
(which is true in both Ember.RSVP land and native Promise land).Fixes ember-cli/ember-cli-mocha#233
Fixes #259