Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX lts-2-8] Allow canceling items queued by run.schedule. #14550

Merged
merged 1 commit into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/ember-metal/lib/run_loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ run.end = function() {
will be resolved on the target object at the time the scheduled item is
invoked allowing you to change the target function.
@param {Object} [arguments*] Optional arguments to be passed to the queued method.
@return {void}
@return {*} Timer information for use in cancelling, see `run.cancel`.
@public
*/
run.schedule = function(/* queue, target, method */) {
Expand All @@ -269,7 +269,8 @@ run.schedule = function(/* queue, target, method */) {
`You will need to wrap any code with asynchronous side-effects in a run`,
run.currentRunLoop || !isTesting()
);
backburner.schedule(...arguments);

return backburner.schedule(...arguments);
};

// Used by global test teardown
Expand Down
11 changes: 11 additions & 0 deletions packages/ember-metal/tests/run_loop/schedule_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ QUnit.test('scheduling item in queue should defer until finished', function() {
equal(cnt, 2, 'should flush actions now');
});

QUnit.test('a scheduled item can be canceled', function(assert) {
let hasRan = false;

run(() => {
let cancelId = run.schedule('actions', () => hasRan = true);
run.cancel(cancelId);
});

assert.notOk(hasRan, 'should not have ran callback run');
});

QUnit.test('nested runs should queue each phase independently', function() {
let cnt = 0;

Expand Down