Skip to content

Commit 84c5c0b

Browse files
committedSep 23, 2020
fix(timeout): allow synchronous observable as source
- closes #5746
1 parent 60080c3 commit 84c5c0b

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed
 

‎spec/observables/dom/webSocket-spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,11 @@ describe('webSocket', () => {
694694
});
695695

696696
describe('node constructor', () => {
697-
698697
it('should send and receive messages', () => {
699698
let messageReceived = false;
700699
const subject = webSocket<string>(<any>{
701700
url: 'ws://mysocket',
702-
WebSocketCtor: (url: string, protocol: string): MockWebSocket => {
703-
return new MockWebSocket(url, protocol);
704-
}
701+
WebSocketCtor: MockWebSocket
705702
});
706703

707704
subject.next('ping');

‎spec/operators/timeout-spec.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ describe('timeout operator', () => {
179179
});
180180
});
181181

182+
it('should work with synchronous observable', () => {
183+
expect(() => {
184+
of(1).pipe(timeout(10)).subscribe();
185+
}).to.not.throw();
186+
});
187+
182188
describe('config', () => {
183189
it('should timeout after a specified timeout period', () => {
184190
rxTestScheduler.run(({ cold, expectObservable, expectSubscriptions, time }) => {
@@ -418,7 +424,7 @@ describe('timeout operator', () => {
418424
const expected = ' -----x-y-z-| ';
419425

420426
const result = source.pipe(timeout({
421-
each: t,
427+
each: t,
422428
with: () => inner,
423429
}));
424430

@@ -439,7 +445,7 @@ describe('timeout operator', () => {
439445

440446
// The the current frame is zero.
441447
const result = source.pipe(timeout({
442-
first: new Date(t),
448+
first: new Date(t),
443449
with: () => inner,
444450
}));
445451

@@ -459,7 +465,7 @@ describe('timeout operator', () => {
459465
const expected = ' ---a---b----x-y-| ';
460466

461467
const result = source.pipe(timeout({
462-
each: t,
468+
each: t,
463469
with: () => inner, }));
464470

465471
expectObservable(result).toBe(expected);

‎src/internal/operators/timeout.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export function timeout<T, R, M>(config: number | Date | TimeoutConfig<T, R, M>,
363363
subscriber,
364364
(value) => {
365365
// clear the timer so we can emit and start another one.
366-
timerSubscription.unsubscribe();
366+
timerSubscription?.unsubscribe();
367367
seen++;
368368
// Emit
369369
subscriber.next((lastValue = value));
@@ -373,6 +373,9 @@ export function timeout<T, R, M>(config: number | Date | TimeoutConfig<T, R, M>,
373373
undefined,
374374
undefined,
375375
() => {
376+
if (!timerSubscription?.closed) {
377+
timerSubscription?.unsubscribe();
378+
}
376379
// Be sure not to hold the last value in memory after unsubscription
377380
// it could be quite large.
378381
lastValue = null;

‎wallaby.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = function (wallaby) {
44
'tsconfig.base.json',
55
'tsconfig.json',
66
'src/**/*.ts',
7-
{ pattern: 'spec/helpers/*.ts', instrument: false, load: true }
7+
{ pattern: 'spec/helpers/!(*-spec).ts', instrument: false, load: true }
88
],
99

1010
tests: ['spec/**/*-spec.ts'],
@@ -20,6 +20,13 @@ module.exports = function (wallaby) {
2020

2121
workers: { initial: 2, regular: 1 },
2222

23+
compilers: {
24+
'**/*.ts?(x)': wallaby.compilers.typeScript({
25+
module: 'commonjs',
26+
target: 'esnext'
27+
})
28+
},
29+
2330
setup: function (w) {
2431
if (!global._tsconfigPathsRegistered) {
2532
var tsConfigPaths = require('tsconfig-paths');

0 commit comments

Comments
 (0)
Please sign in to comment.