Skip to content

Commit

Permalink
Address PR comment
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Lund <[email protected]>
  • Loading branch information
tlund101 committed Feb 10, 2024
1 parent 319564c commit 2d0faf8
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/implementation/Client/GRPCClient/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ limitations under the License.
*/

import GRPCClient from "./GRPCClient";
import * as grpc from "@grpc/grpc-js";
import {
GetConfigurationRequest,
GetConfigurationResponse,
Expand All @@ -38,26 +37,18 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
}

async get(storeName: string, keys: string[], metadataObj?: KeyValueType): Promise<GetConfigurationResponseResult> {
const metadata = new grpc.Metadata();

const msg = new GetConfigurationRequest();
msg.setStoreName(storeName);

if (keys && keys.length > 0) {
msg.setKeysList(keys.filter((i) => i !== ""));
}

if (metadataObj) {
for (const [key, value] of Object.entries(metadataObj)) {
metadata.add(key, value);
}
addMetadataToMap(msg.getMetadataMap(), metadataObj);
}
addMetadataToMap(msg.getMetadataMap(), metadataObj);

const client = await this.client.getClient();

return new Promise((resolve, reject) => {
client.getConfiguration(msg, metadata, (err, res: GetConfigurationResponse) => {
client.getConfiguration(msg, (err, res: GetConfigurationResponse) => {
if (err) {
return reject(err);
}
Expand Down Expand Up @@ -100,8 +91,6 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
keys?: string[],
metadataObj?: KeyValueType,
): Promise<SubscribeConfigurationStream> {
const metadata = new grpc.Metadata();

const msg = new SubscribeConfigurationRequest();
msg.setStoreName(storeName);

Expand All @@ -110,21 +99,15 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
} else {
msg.setKeysList([]);
}

if (metadataObj) {
for (const [key, value] of Object.entries(metadataObj)) {
metadata.add(key, value);
}
addMetadataToMap(msg.getMetadataMap(), metadataObj);
}
addMetadataToMap(msg.getMetadataMap(), metadataObj);

const client = await this.client.getClient();

// Open a stream. Note that this is a never-ending stream
// and will stay open as long as the client is open
// we will thus create a set with our listeners so we don't
// break on multi listeners
const stream = client.subscribeConfiguration(msg, metadata);
const stream = client.subscribeConfiguration(msg);
let streamId: string;

stream.on("data", async (data: SubscribeConfigurationResponse) => {
Expand Down

0 comments on commit 2d0faf8

Please sign in to comment.