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 18, 2018
1 parent ca65b84 commit 20d5297
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
16 changes: 13 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 @@ -428,12 +433,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
4 changes: 3 additions & 1 deletion packages/ember-metal/tests/run_loop/sync_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ 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);
}
Expand Down

0 comments on commit 20d5297

Please sign in to comment.