From d384c83a120dcf82f2aca230a9e25165e5206f7b Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 24 Apr 2023 11:38:28 +0200 Subject: [PATCH] config-loader: review fixes in RemoteConfigSource and StaticConfigSource Signed-off-by: Patrik Oldsberg --- .../src/sources/RemoteConfigSource.ts | 4 ++-- .../src/sources/StaticConfigSource.ts | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/config-loader/src/sources/RemoteConfigSource.ts b/packages/config-loader/src/sources/RemoteConfigSource.ts index 71aa800e59..22d9d1ca69 100644 --- a/packages/config-loader/src/sources/RemoteConfigSource.ts +++ b/packages/config-loader/src/sources/RemoteConfigSource.ts @@ -62,9 +62,9 @@ export interface RemoteConfigSourceOptions { url: string; /** - * The interval in seconds to reload the config from the remote URL. + * How often to reload the config from the remote URL, defaults to 1 minute. * - * Set to Infinity to disable reloading. + * Set to Infinity to disable reloading, for example `{ days: Infinity }`. */ reloadInterval?: HumanDuration; diff --git a/packages/config-loader/src/sources/StaticConfigSource.ts b/packages/config-loader/src/sources/StaticConfigSource.ts index 68ccc3353a..e549f06391 100644 --- a/packages/config-loader/src/sources/StaticConfigSource.ts +++ b/packages/config-loader/src/sources/StaticConfigSource.ts @@ -60,11 +60,17 @@ class StaticObservableConfigSource implements ConfigSource { }, }); - options?.signal?.addEventListener('abort', () => { - sub.unsubscribe(); - queue.length = 0; - deferred.resolve(); - }); + const signal = options?.signal; + if (signal) { + const onAbort = () => { + sub.unsubscribe(); + queue.length = 0; + deferred.resolve(); + signal.removeEventListener('abort', onAbort); + }; + + signal.addEventListener('abort', onAbort); + } for (;;) { await deferred.promise; @@ -109,11 +115,8 @@ export class StaticConfigSource implements ConfigSource { }; } - if (isObservable(data)) { - return new StaticObservableConfigSource( - data as Observable, - context, - ); + if (isObservable(data)) { + return new StaticObservableConfigSource(data, context); } if (isAsyncIterable(data)) {