Skip to content

Commit 1dead40

Browse files
update
1 parent 5525244 commit 1dead40

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IKeyValueAdapter } from "./IKeyValueAdapter.js";
99
import { JsonKeyValueAdapter } from "./JsonKeyValueAdapter.js";
1010
import { DEFAULT_REFRESH_INTERVAL_IN_MS, MIN_REFRESH_INTERVAL_IN_MS } from "./RefreshOptions.js";
1111
import { Disposable } from "./common/disposable.js";
12-
import { Lock } from "./common/lock.js";
12+
import { ExclusiveExecutor } from "./common/mutex.js";
1313
import { FEATURE_FLAGS_KEY_NAME, FEATURE_MANAGEMENT_KEY_NAME } from "./featureManagement/constants.js";
1414
import { AzureKeyVaultKeyValueAdapter } from "./keyvault/AzureKeyVaultKeyValueAdapter.js";
1515
import { RefreshTimer } from "./refresh/RefreshTimer.js";
@@ -41,7 +41,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
4141
#isInitialLoadCompleted: boolean = false;
4242

4343
// Refresh
44-
#refreshLock: Lock = new Lock(); // lock to prevent "concurrent" async refresh
44+
#refreshExecutor: ExclusiveExecutor = new ExclusiveExecutor();
4545

4646
#refreshInterval: number = DEFAULT_REFRESH_INTERVAL_IN_MS;
4747
#onRefreshListeners: Array<() => any> = [];
@@ -353,7 +353,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
353353
throw new Error("Refresh is not enabled for key-values or feature flags.");
354354
}
355355

356-
await this.#refreshLock.execute(this.#refreshTasks.bind(this));
356+
await this.#refreshExecutor.execute(this.#refreshTasks.bind(this));
357357
}
358358

359359
async #refreshTasks(): Promise<void> {

src/common/lock.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/common/mutex.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
export class ExclusiveExecutor {
5+
isExecuting = false;
6+
7+
/**
8+
* Execute the given function exclusively. If there is any previous execution in progress, the new execution will be aborted.
9+
*/
10+
async execute(fn) {
11+
if (this.isExecuting) {
12+
return; // do nothing
13+
}
14+
this.isExecuting = true;
15+
try {
16+
await fn();
17+
} finally {
18+
this.isExecuting = false;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)