This repository was archived by the owner on Jan 10, 2025. It is now read-only.
Open
Conversation
added 17 commits
December 22, 2022 01:12
…/ev-server into feature/lightlog
ClaudeROSSI
commented
Jan 4, 2023
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); | ||
| } | ||
| } | ||
| } | ||
|
|
Contributor
Author
There was a problem hiding this comment.
@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!
ClaudeROSSI
commented
Jan 4, 2023
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; | ||
| } | ||
|
|
Contributor
Author
There was a problem hiding this comment.
I remove the pending command from the cache as soon as we use it!
ClaudeROSSI
commented
Jan 4, 2023
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) => { |
Contributor
Author
There was a problem hiding this comment.
@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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.