-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logperf5 #4030
base: master-qa
Are you sure you want to change the base?
Logperf5 #4030
Conversation
…/ev-server into feature/lightlog
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); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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!
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; | ||
} | ||
|
There was a problem hiding this comment.
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!
public async sendMessageAndWaitForResult(messageID: string, command: Command, data: Record<string, any>): Promise<unknown> { | ||
// Create a pending promise | ||
const pendingPromise = new Promise((resolve, reject) => { |
There was a problem hiding this comment.
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
No description provided.