grpc-js: xDS Client: cache updates to pass them to new watchers

This commit is contained in:
Michael Lumish 2020-07-23 10:27:01 -07:00
parent 8d759b30ab
commit fc2fd00da7

View File

@ -105,6 +105,7 @@ export class XdsClient {
> = new Map<string, Watcher<ClusterLoadAssignment__Output>[]>();
private lastEdsVersionInfo = '';
private lastEdsNonce = '';
private latestEdsResponses: ClusterLoadAssignment__Output[] = [];
constructor(
private targetName: string,
@ -206,6 +207,7 @@ export class XdsClient {
}
this.lastEdsVersionInfo = message.version_info;
this.lastEdsNonce = message.nonce;
this.latestEdsResponses = edsResponses;
this.ackEds();
break;
}
@ -357,6 +359,18 @@ export class XdsClient {
if (addedServiceName) {
this.updateEdsNames();
}
/* If we have already received an update for the requested edsServiceName,
* immediately pass that update along to the watcher */
for (const message of this.latestEdsResponses) {
if (message.cluster_name === edsServiceName) {
/* These updates normally occur asynchronously, so we ensure that
* the same happens here */
process.nextTick(() => {
watcher.onValidUpdate(message);
});
}
}
}
removeEndpointWatcher(