config-loader: review fixes in RemoteConfigSource and StaticConfigSource

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-04-24 11:38:28 +02:00
parent ae57dd4ac0
commit d384c83a12
2 changed files with 15 additions and 12 deletions
@@ -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;
@@ -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<JsonObject>,
context,
);
if (isObservable<JsonObject>(data)) {
return new StaticObservableConfigSource(data, context);
}
if (isAsyncIterable(data)) {