@@ -9,6 +9,8 @@ export type updateDiscoveredEndpointInCacheOptions = {
9
9
identifiers ?: Map < String , String > ;
10
10
} ;
11
11
12
+ const sleep = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
13
+
12
14
export const updateDiscoveredEndpointInCache = async (
13
15
config : EndpointDiscoveryClientResolvedConfig ,
14
16
options : updateDiscoveredEndpointInCacheOptions
@@ -19,12 +21,15 @@ export const updateDiscoveredEndpointInCache = async (
19
21
const { commandName, identifiers } = options ;
20
22
const cacheKey = await getCacheKey ( commandName , client ?. config , { identifiers } ) ;
21
23
22
- const endpoints = endpointCache . get ( cacheKey ) ;
23
- if ( endpoints && endpoints . length === 1 && endpoints [ 0 ] . Address === "" ) {
24
- // endpoint operation is being made but response not yet received
25
- // or endpoint operation just failed in 1 minute.
26
- return ;
27
- } else if ( endpoints && endpoints . length > 0 ) {
24
+ let endpoints = endpointCache . get ( cacheKey ) ;
25
+
26
+ // Wait for other endpoint operations to complete before making new calls.
27
+ while ( endpoints && endpoints . length === 1 && endpoints [ 0 ] . Address === "" ) {
28
+ await sleep ( 1000 ) ;
29
+ endpoints = endpointCache . get ( cacheKey ) ;
30
+ }
31
+
32
+ if ( endpoints && endpoints . length > 0 ) {
28
33
// Endpoint record is present in cache.
29
34
return ;
30
35
} else {
0 commit comments