Skip to content

Commit

Permalink
Merge pull request #5 from shiv3/fix/concurrent-connect
Browse files Browse the repository at this point in the history
Fix to connect concurrency
  • Loading branch information
shiv3 committed Aug 20, 2024
2 parents 03ca03d + adbfd5f commit 0b687b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/components/TopPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ interface transactionInfo {
const ExperimentalView: React.FC<ExperimentalProps> = ({cps, tagIDs}) => {
const handleAllConnect = () => {
console.log("Connecting all charge points");
cps.forEach((cp) => {
cp.connect();
});
const chunk = 100;
cps.flatMap((_, i, a) => i % chunk ? [] : [a.slice(i, i + chunk)]).forEach((cps) => {
Promise.all(cps.map((cp) => cp.connect()))
})
}

const handleAllDisconnect = () => {
Expand Down
15 changes: 8 additions & 7 deletions src/cp/ChargePoint.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Connector } from "./Connector";
import { OCPPWebSocket } from "./OCPPWebSocket";
import { OCPPMessageHandler } from "./OCPPMessageHandler";
import { Logger } from "./Logger";
import { OCPPStatus, OCPPAvailability } from "./OcppTypes";
import { Transaction } from "./Transaction.ts";
import {Connector} from "./Connector";
import {OCPPWebSocket} from "./OCPPWebSocket";
import {OCPPMessageHandler} from "./OCPPMessageHandler";
import {Logger} from "./Logger";
import {OCPPStatus, OCPPAvailability} from "./OcppTypes";
import {Transaction} from "./Transaction.ts";
import * as ocpp from "./OcppTypes.ts";

export class ChargePoint {
Expand All @@ -15,7 +15,8 @@ export class ChargePoint {

public _status: OCPPStatus = OCPPStatus.Unavailable;
private _error: string = "";
public _errorCallback: (error: string) => void = () => {};
public _errorCallback: (error: string) => void = () => {
};

private _heartbeat: number | null = null;
private _statusChangeCallback:
Expand Down

0 comments on commit 0b687b1

Please sign in to comment.