Skip to content

Commit

Permalink
fix(timeout): allow synchronous observable as source
Browse files Browse the repository at this point in the history
- closes #5746
  • Loading branch information
kwonoj committed Sep 23, 2020
1 parent 60080c3 commit 84c5c0b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 1 addition & 4 deletions spec/observables/dom/webSocket-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,11 @@ describe('webSocket', () => {
});

describe('node constructor', () => {

it('should send and receive messages', () => {
let messageReceived = false;
const subject = webSocket<string>(<any>{
url: 'ws://mysocket',
WebSocketCtor: (url: string, protocol: string): MockWebSocket => {
return new MockWebSocket(url, protocol);
}
WebSocketCtor: MockWebSocket
});

subject.next('ping');
Expand Down
12 changes: 9 additions & 3 deletions spec/operators/timeout-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ describe('timeout operator', () => {
});
});

it('should work with synchronous observable', () => {
expect(() => {
of(1).pipe(timeout(10)).subscribe();
}).to.not.throw();
});

describe('config', () => {
it('should timeout after a specified timeout period', () => {
rxTestScheduler.run(({ cold, expectObservable, expectSubscriptions, time }) => {
Expand Down Expand Up @@ -418,7 +424,7 @@ describe('timeout operator', () => {
const expected = ' -----x-y-z-| ';

const result = source.pipe(timeout({
each: t,
each: t,
with: () => inner,
}));

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

// The the current frame is zero.
const result = source.pipe(timeout({
first: new Date(t),
first: new Date(t),
with: () => inner,
}));

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

const result = source.pipe(timeout({
each: t,
each: t,
with: () => inner, }));

expectObservable(result).toBe(expected);
Expand Down
5 changes: 4 additions & 1 deletion src/internal/operators/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export function timeout<T, R, M>(config: number | Date | TimeoutConfig<T, R, M>,
subscriber,
(value) => {
// clear the timer so we can emit and start another one.
timerSubscription.unsubscribe();
timerSubscription?.unsubscribe();
seen++;
// Emit
subscriber.next((lastValue = value));
Expand All @@ -373,6 +373,9 @@ export function timeout<T, R, M>(config: number | Date | TimeoutConfig<T, R, M>,
undefined,
undefined,
() => {
if (!timerSubscription?.closed) {
timerSubscription?.unsubscribe();
}
// Be sure not to hold the last value in memory after unsubscription
// it could be quite large.
lastValue = null;
Expand Down
9 changes: 8 additions & 1 deletion wallaby.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function (wallaby) {
'tsconfig.base.json',
'tsconfig.json',
'src/**/*.ts',
{ pattern: 'spec/helpers/*.ts', instrument: false, load: true }
{ pattern: 'spec/helpers/!(*-spec).ts', instrument: false, load: true }
],

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

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

compilers: {
'**/*.ts?(x)': wallaby.compilers.typeScript({
module: 'commonjs',
target: 'esnext'
})
},

setup: function (w) {
if (!global._tsconfigPathsRegistered) {
var tsConfigPaths = require('tsconfig-paths');
Expand Down

0 comments on commit 84c5c0b

Please sign in to comment.