Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Logperf5#4030

Open
ClaudeROSSI wants to merge 22 commits intomaster-qafrom
logperf5
Open

Logperf5#4030
ClaudeROSSI wants to merge 22 commits intomaster-qafrom
logperf5

Conversation

@ClaudeROSSI
Copy link
Contributor

No description provided.

@ClaudeROSSI ClaudeROSSI requested review from lmargaron and r0mux January 4, 2023 15:59
Comment on lines 17 to 52
export class OcppPendingCommand {
private command;
private resolveCallback: FctOCPPResponse;
private rejectCallback: FctOCPPReject;
private timer: NodeJS.Timeout;

public constructor(command: string, resolveCallback: FctOCPPResponse, rejectCallback: FctOCPPReject, timer: NodeJS.Timeout) {
this.command = command;
this.resolveCallback = resolveCallback;
this.rejectCallback = rejectCallback;
this.timer = timer;
}

public getCommand(): string {
return this.command;
}

public resolve(payload: Record<string, unknown> | string): void {
this.clearTimer();
this.resolveCallback(payload);
}

public reject(error: OCPPError): void {
this.clearTimer();
this.rejectCallback(error);
}

private clearTimer() {
const timer = this.timer;
if (timer) {
this.timer = null;
clearTimeout(timer);
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmargaron , @Ramzay : Here is the main change that I'm trying to introduce to improve the code maintainability! ;)

The class OcppPendingCommand replaces the former ocppRequest type!

Comment on lines +242 to +250
private consumePendingOcppCommands(messageID: string) {
const pendingOcppCommand = this.pendingOcppCommands[messageID];
if (pendingOcppCommand) {
// It can be consumed only once - so we remove it from the cache
delete this.pendingOcppCommands[messageID];
}
return pendingOcppCommand;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove the pending command from the cache as soon as we use it!

Comment on lines +101 to +103
public async sendMessageAndWaitForResult(messageID: string, command: Command, data: Record<string, any>): Promise<unknown> {
// Create a pending promise
const pendingPromise = new Promise((resolve, reject) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ramzay , @lmargaron : I couln't get rid of the new Promise()!

But now the logic is isolated in a dedicated method which only handles message of type: OCPPMessageType.CALL_MESSAGE

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant