From 03d0f9fb431702ddfbb264edd3d7f466a0ca0ce6 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sat, 4 Nov 2017 11:15:10 +1000 Subject: [PATCH] fix(scheduler): prevent unwanted clearInterval In AsyncAction, this.pending was assigned before the call to recycleAsyncId. That prevented the interval from being re-used resulting in the interval being cleared and re-created for each notification. Closes #3042 --- spec/schedulers/AsapScheduler-spec.ts | 6 ++++-- src/scheduler/AsyncAction.ts | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/schedulers/AsapScheduler-spec.ts b/spec/schedulers/AsapScheduler-spec.ts index d2beb20fb0..7651f323e2 100644 --- a/spec/schedulers/AsapScheduler-spec.ts +++ b/spec/schedulers/AsapScheduler-spec.ts @@ -43,7 +43,8 @@ describe('Scheduler.asap', () => { it('should reuse the interval for recursively scheduled actions with the same delay', () => { const sandbox = sinon.sandbox.create(); const fakeTimer = sandbox.useFakeTimers(); - const stubSetInterval = sinon.stub(global, 'setInterval').callThrough(); + // callThrough is missing from the declarations installed by the typings tool in stable + const stubSetInterval = ( sinon.stub(global, 'setInterval')).callThrough(); function dispatch(state: any): void { state.index += 1; if (state.index < 3) { @@ -68,7 +69,8 @@ describe('Scheduler.asap', () => { it('should not reuse the interval for recursively scheduled actions with a different delay', () => { const sandbox = sinon.sandbox.create(); const fakeTimer = sandbox.useFakeTimers(); - const stubSetInterval = sinon.stub(global, 'setInterval').callThrough(); + // callThrough is missing from the declarations installed by the typings tool in stable + const stubSetInterval = ( sinon.stub(global, 'setInterval')).callThrough(); function dispatch(state: any): void { state.index += 1; state.period -= 1; diff --git a/src/scheduler/AsyncAction.ts b/src/scheduler/AsyncAction.ts index 31a95c73ef..432edbab2a 100644 --- a/src/scheduler/AsyncAction.ts +++ b/src/scheduler/AsyncAction.ts @@ -29,10 +29,6 @@ export class AsyncAction extends Action { // Always replace the current state with the new state. this.state = state; - // Set the pending flag indicating that this action has been scheduled, or - // has recursively rescheduled itself. - this.pending = true; - const id = this.id; const scheduler = this.scheduler; @@ -61,6 +57,10 @@ export class AsyncAction extends Action { this.id = this.recycleAsyncId(scheduler, id, delay); } + // Set the pending flag indicating that this action has been scheduled, or + // has recursively rescheduled itself. + this.pending = true; + this.delay = delay; // If this action has already an async Id, don't request a new one. this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);