File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { IKeyValueAdapter } from "./IKeyValueAdapter.js";
99import { JsonKeyValueAdapter } from "./JsonKeyValueAdapter.js" ;
1010import { DEFAULT_REFRESH_INTERVAL_IN_MS , MIN_REFRESH_INTERVAL_IN_MS } from "./RefreshOptions.js" ;
1111import { Disposable } from "./common/disposable.js" ;
12+ import { Lock } from "./common/lock.js"
1213import { FEATURE_FLAGS_KEY_NAME , FEATURE_MANAGEMENT_KEY_NAME } from "./featureManagement/constants.js" ;
1314import { AzureKeyVaultKeyValueAdapter } from "./keyvault/AzureKeyVaultKeyValueAdapter.js" ;
1415import { RefreshTimer } from "./refresh/RefreshTimer.js" ;
@@ -40,6 +41,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
4041 #isInitialLoadCompleted: boolean = false ;
4142
4243 // Refresh
44+ #refreshLock: Lock = new Lock ( ) ; // lock to prevent "concurrent" async refresh
45+
4346 #refreshInterval: number = DEFAULT_REFRESH_INTERVAL_IN_MS ;
4447 #onRefreshListeners: Array < ( ) => any > = [ ] ;
4548 /**
@@ -350,6 +353,10 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
350353 throw new Error ( "Refresh is not enabled for key-values or feature flags." ) ;
351354 }
352355
356+ this . #refreshLock. execute ( this . #refreshTasks) ;
357+ }
358+
359+ async #refreshTasks( ) : Promise < void > {
353360 const refreshTasks : Promise < boolean > [ ] = [ ] ;
354361 if ( this . #refreshEnabled) {
355362 refreshTasks . push ( this . #refreshKeyValues( ) ) ;
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT license.
3+
4+ export class Lock {
5+ #locked = false ;
6+
7+ async execute ( fn ) {
8+ if ( this . #locked) {
9+ return ; // do nothing
10+ }
11+ this . #locked = true ;
12+ try {
13+ await fn ( ) ;
14+ } finally {
15+ this . #locked = false ;
16+ }
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments