Skip to content

Commit

Permalink
[BUGFIX beta] Deprecate scheduling into sync queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jan 16, 2018
1 parent 8db050f commit 3032886
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
18 changes: 15 additions & 3 deletions packages/ember-metal/lib/run_loop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, isTesting } from 'ember-debug';
import { assert, deprecate, isTesting } from 'ember-debug';
import {
onErrorTarget
} from './error_handler';
Expand Down Expand Up @@ -277,12 +277,17 @@ run.end = function() {
@return {*} Timer information for use in canceling, see `run.cancel`.
@public
*/
run.schedule = function(/* queue, target, method */) {
run.schedule = function(queue /*, target, method */) {
assert(
`You have turned on testing mode, which disabled the run-loop's autorun. ` +
`You will need to wrap any code with asynchronous side-effects in a run`,
run.currentRunLoop || !isTesting()
);
deprecate(
`Scheduling into the '${queue}' run loop queue is deprecated.`,
queue !== 'sync',
{ id: 'ember-metal.run.sync', until: '3.5.0' }
);

return backburner.schedule(...arguments);
};
Expand Down Expand Up @@ -351,6 +356,8 @@ run.later = function(/*target, method*/) {
@private
*/
run.sync = function() {
deprecate('Invoking `run.sync()` is deprecated.', false, { id: 'ember-metal.run.sync', until: '3.5.0' });

if (backburner.currentInstance) {
backburner.currentInstance.queues.sync.flush();
}
Expand Down Expand Up @@ -453,12 +460,17 @@ run.once = function(...args) {
@return {Object} Timer information for use in canceling, see `run.cancel`.
@public
*/
run.scheduleOnce = function(/*queue, target, method*/) {
run.scheduleOnce = function(queue /*, target, method*/) {
assert(
`You have turned on testing mode, which disabled the run-loop's autorun. ` +
`You will need to wrap any code with asynchronous side-effects in a run`,
run.currentRunLoop || !isTesting()
);
deprecate(
`Scheduling into the '${queue}' run loop queue is deprecated.`,
queue !== 'sync',
{ id: 'ember-metal.run.sync', until: '3.5.0' }
);
return backburner.scheduleOnce(...arguments);
};

Expand Down
20 changes: 12 additions & 8 deletions packages/ember-metal/tests/run_loop/schedule_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ moduleFor('system/run_loop/schedule_test', class extends AbstractTestCase {
let runLoop = run.currentRunLoop;
assert.ok(runLoop, 'run loop present');

run.schedule('sync', () => {
order.push('sync');
assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
});
expectDeprecation(() => {
run.schedule('sync', () => {
order.push('sync');
assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
});
}, `Scheduling into the 'sync' run loop queue is deprecated.`);

run.schedule('actions', () => {
order.push('actions');
Expand All @@ -62,10 +64,12 @@ moduleFor('system/run_loop/schedule_test', class extends AbstractTestCase {
assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
});

run.schedule('sync', () => {
order.push('sync');
assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
});
expectDeprecation(() => {
run.schedule('sync', () => {
order.push('sync');
assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
});
}, `Scheduling into the 'sync' run loop queue is deprecated.`);
});

run.schedule('destroy', () => {
Expand Down
16 changes: 10 additions & 6 deletions packages/ember-metal/tests/run_loop/sync_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@ moduleFor('system/run_loop/sync_test', class extends AbstractTestCase {

function syncfunc() {
if (++cnt < 5) {
run.schedule('sync', syncfunc);
expectDeprecation(() => {
run.schedule('sync', syncfunc);
}, `Scheduling into the 'sync' run loop queue is deprecated.`);
}
run.schedule('actions', cntup);
}

syncfunc();

assert.equal(cnt, 1, 'should not run action yet');
run.sync();
expectDeprecation(() => {
run.sync();
}, 'Invoking `run.sync()` is deprecated.');

assert.equal(cnt, 5, 'should have run sync queue continuously');
});

assert.equal(cnt, 10, 'should flush actions now too');
}

['@test calling sync() outside a run loop does not cause an error'](assert) {
assert.expect(0);

run.sync();
['@test calling sync() outside a run loop does not cause an error']() {
expectDeprecation(() => {
run.sync();
}, 'Invoking `run.sync()` is deprecated.');
}
});

0 comments on commit 3032886

Please sign in to comment.