From 7b6a0f42bbaa22610bf4007ae15971ffb2d7a61e Mon Sep 17 00:00:00 2001 From: Christoph Guttandin Date: Wed, 4 May 2022 09:02:18 +0200 Subject: [PATCH] fix(zip): handle when unsubscribe is called from within next --- packages/rxjs/spec/observables/zip-spec.ts | 26 +++++++++++++++++++- packages/rxjs/src/internal/observable/zip.ts | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/rxjs/spec/observables/zip-spec.ts b/packages/rxjs/spec/observables/zip-spec.ts index 7a483edd0e..40d35004ca 100644 --- a/packages/rxjs/spec/observables/zip-spec.ts +++ b/packages/rxjs/spec/observables/zip-spec.ts @@ -1,6 +1,6 @@ /** @prettier */ import { expect } from 'chai'; -import { queueScheduler as rxQueueScheduler, zip, from, scheduled } from 'rxjs'; +import { queueScheduler as rxQueueScheduler, zip, from, scheduled, of, config, concat, NEVER, first, delay, filter, GlobalConfig } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; import { observableMatcher } from '../helpers/observableMatcher'; @@ -630,4 +630,28 @@ describe('zip', () => { expect(results).to.deep.equal(['done']); }); + + describe('with a registered notificaiton handler', () => { + let onStoppedNotification: GlobalConfig['onStoppedNotification']; + + beforeEach(() => onStoppedNotification = config.onStoppedNotification); + + afterEach(() => config.onStoppedNotification = onStoppedNotification); + + it('should handle when unsubscribing from within a next handler', (done) => { + let error: any = null; + + config.onStoppedNotification = (notification) => { + if (notification.kind === 'E') { + error = notification.error; + + done(notification.error); + } + }; + + const source$ = concat(of(1), NEVER); + + zip(source$).pipe(first(), delay(1), filter(() => error === null)).subscribe(() => done()); + }); + }); }); diff --git a/packages/rxjs/src/internal/observable/zip.ts b/packages/rxjs/src/internal/observable/zip.ts index be3af3ace3..6fdb87c233 100644 --- a/packages/rxjs/src/internal/observable/zip.ts +++ b/packages/rxjs/src/internal/observable/zip.ts @@ -88,7 +88,7 @@ export function zip(...args: unknown[]): Observable { // If any one of the sources is both complete and has an empty buffer // then we complete the result. This is because we cannot possibly have // any more values to zip together. - if (buffers.some((buffer, i) => !buffer.length && completed[i])) { + if (buffers?.some((buffer, i) => !buffer.length && completed[i])) { destination.complete(); } }