Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/AzureAppConfigurationImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IKeyValueAdapter } from "./IKeyValueAdapter.js";
import { JsonKeyValueAdapter } from "./JsonKeyValueAdapter.js";
import { DEFAULT_REFRESH_INTERVAL_IN_MS, MIN_REFRESH_INTERVAL_IN_MS } from "./RefreshOptions.js";
import { Disposable } from "./common/disposable.js";
import { Lock } from "./common/lock.js";
import { FEATURE_FLAGS_KEY_NAME, FEATURE_MANAGEMENT_KEY_NAME } from "./featureManagement/constants.js";
import { AzureKeyVaultKeyValueAdapter } from "./keyvault/AzureKeyVaultKeyValueAdapter.js";
import { RefreshTimer } from "./refresh/RefreshTimer.js";
Expand Down Expand Up @@ -40,6 +41,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
#isInitialLoadCompleted: boolean = false;

// Refresh
#refreshLock: Lock = new Lock(); // lock to prevent "concurrent" async refresh

#refreshInterval: number = DEFAULT_REFRESH_INTERVAL_IN_MS;
#onRefreshListeners: Array<() => any> = [];
/**
Expand Down Expand Up @@ -350,6 +353,10 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
throw new Error("Refresh is not enabled for key-values or feature flags.");
}

await this.#refreshLock.execute(this.#refreshTasks.bind(this));
}

async #refreshTasks(): Promise<void> {
const refreshTasks: Promise<boolean>[] = [];
if (this.#refreshEnabled) {
refreshTasks.push(this.#refreshKeyValues());
Expand Down
18 changes: 18 additions & 0 deletions src/common/lock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export class Lock {
#locked = false;

async execute(fn) {
if (this.#locked) {
return; // do nothing
}
this.#locked = true;
try {
await fn();
} finally {
this.#locked = false;
}
}
}