Skip to content

Commit

Permalink
Merge pull request #3667 from cartant/issue-3605-stable
Browse files Browse the repository at this point in the history
fix(delay): fix memory leak (in stable)
  • Loading branch information
benlesh authored May 21, 2018
2 parents 21a59a7 + 9d1ba14 commit 6b08b13
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
34 changes: 33 additions & 1 deletion spec/operators/delay-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { expect } from 'chai';
import * as sinon from 'sinon';
import * as Rx from '../../dist/package/Rx';
import { delay, repeatWhen, skip, take, tap } from '../../dist/package/operators';
import marbleTestingSignature = require('../helpers/marble-testing'); // tslint:disable-line:no-require-imports

declare const { asDiagram, time };
Expand Down Expand Up @@ -147,4 +150,33 @@ describe('Observable.prototype.delay', () => {

expectObservable(result).toBe(expected);
});
});

it('should unsubscribe scheduled actions after execution', () => {
let subscribeSpy: any = null;
const counts: number[] = [];

const e1 = cold('a|');
const expected = '--a-(a|)';
const duration = time('-|');
const result = e1.pipe(
repeatWhen(notifications => {
const delayed = notifications.pipe(delay(duration, rxTestScheduler));
subscribeSpy = sinon.spy(delayed['source'], 'subscribe');
return delayed;
}),
skip(1),
take(2),
tap({
next() {
const [[subscriber]] = subscribeSpy.args;
counts.push(subscriber._subscriptions.length);
},
complete() {
expect(counts).to.deep.equal([1, 1]);
}
})
);

expectObservable(result).toBe(expected);
});
});
1 change: 1 addition & 0 deletions src/operators/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class DelaySubscriber<T> extends Subscriber<T> {
const delay = Math.max(0, queue[0].time - scheduler.now());
this.schedule(state, delay);
} else {
this.unsubscribe();
source.active = false;
}
}
Expand Down

0 comments on commit 6b08b13

Please sign in to comment.