Skip to content

Commit 0b687b1

Browse files
authored
Merge pull request #5 from shiv3/fix/concurrent-connect
Fix to connect concurrency
2 parents 03ca03d + adbfd5f commit 0b687b1

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/components/TopPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ interface transactionInfo {
6262
const ExperimentalView: React.FC<ExperimentalProps> = ({cps, tagIDs}) => {
6363
const handleAllConnect = () => {
6464
console.log("Connecting all charge points");
65-
cps.forEach((cp) => {
66-
cp.connect();
67-
});
65+
const chunk = 100;
66+
cps.flatMap((_, i, a) => i % chunk ? [] : [a.slice(i, i + chunk)]).forEach((cps) => {
67+
Promise.all(cps.map((cp) => cp.connect()))
68+
})
6869
}
6970

7071
const handleAllDisconnect = () => {

src/cp/ChargePoint.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Connector } from "./Connector";
2-
import { OCPPWebSocket } from "./OCPPWebSocket";
3-
import { OCPPMessageHandler } from "./OCPPMessageHandler";
4-
import { Logger } from "./Logger";
5-
import { OCPPStatus, OCPPAvailability } from "./OcppTypes";
6-
import { Transaction } from "./Transaction.ts";
1+
import {Connector} from "./Connector";
2+
import {OCPPWebSocket} from "./OCPPWebSocket";
3+
import {OCPPMessageHandler} from "./OCPPMessageHandler";
4+
import {Logger} from "./Logger";
5+
import {OCPPStatus, OCPPAvailability} from "./OcppTypes";
6+
import {Transaction} from "./Transaction.ts";
77
import * as ocpp from "./OcppTypes.ts";
88

99
export class ChargePoint {
@@ -15,7 +15,8 @@ export class ChargePoint {
1515

1616
public _status: OCPPStatus = OCPPStatus.Unavailable;
1717
private _error: string = "";
18-
public _errorCallback: (error: string) => void = () => {};
18+
public _errorCallback: (error: string) => void = () => {
19+
};
1920

2021
private _heartbeat: number | null = null;
2122
private _statusChangeCallback:

0 commit comments

Comments
 (0)