From 5a8f653f1a62577c1f52c44353de3441c230f0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 28 Aug 2019 11:13:51 +0200 Subject: [PATCH] Fix "wait for all observables to complete" logic ConfigServiceBase --- src/app/services/config.service.base.ts | 13 ++++++------- src/app/services/config.service.ts | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/services/config.service.base.ts b/src/app/services/config.service.base.ts index 5c640ac..74c1b80 100644 --- a/src/app/services/config.service.base.ts +++ b/src/app/services/config.service.base.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { WebSocketService } from './websocket.service'; -import { Subject, BehaviorSubject, forkJoin } from 'rxjs'; +import { Subject, BehaviorSubject, merge } from 'rxjs'; import { take } from 'rxjs/operators'; @Injectable() @@ -13,12 +13,11 @@ export abstract class ConfigServiceBase { constructor(private webSocketService: WebSocketService) {} init() { - if (this.initDone) { - return; + if (!this.initDone) { + this.waitForMandatoryConfigs(); + this.subscribeConfigKeys(); + this.initDone = true; } - this.waitForMandatoryConfigs(); - this.subscribeConfigKeys(); - this.initDone = true; } waitForMandatoryConfigs() { @@ -28,7 +27,7 @@ export abstract class ConfigServiceBase { firstConfigs.push(config.pipe(take(requiredEmitCount))); }); - forkJoin(firstConfigs).subscribe(undefined, undefined, () => { + merge(...firstConfigs).subscribe(undefined, undefined, () => { this.configDone.next(); this.configDone.complete(); }); diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index a26a801..6d9f576 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { WebSocketService } from './websocket.service'; -import { Subject, BehaviorSubject, forkJoin } from 'rxjs'; +import { Subject, BehaviorSubject, merge } from 'rxjs'; import { ConfigServiceBase } from './config.service.base'; @Injectable() @@ -75,7 +75,7 @@ export class ConfigReadyService { recvdConfigDone.complete(); }); - forkJoin(this.readyNotifiers).subscribe(undefined, undefined, () => { + merge(...this.readyNotifiers).subscribe(undefined, undefined, () => { this.configDone.next(); this.configDone.complete(); });