Skip to content

Commit

Permalink
fix(examples/grid): 🐛 bug where eventListener is added multiple time
Browse files Browse the repository at this point in the history
chore: better setinterval

Signed-off-by: Sacha Froment <[email protected]>

chore: try to fix cache

Signed-off-by: Sacha Froment <[email protected]>

chore: test bench

Signed-off-by: Sacha Froment <[email protected]>

chore: test bench

Signed-off-by: Sacha Froment <[email protected]>
  • Loading branch information
sfroment committed Feb 24, 2025
1 parent ec5b182 commit ff7a5b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
uses: actions/cache@v4
with:
path: ./cache
key: benchmark-${{ runner.os }}-${{ github.run_id }}
key: benchmark-${{ runner.os }}-${{ github.ref }}
restore-keys: |
benchmark-${{ runner.os }}
benchmark-${{ runner.os }}-
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
Expand All @@ -50,6 +50,7 @@ jobs:
gh-pages-branch: main
skip-fetch-gh-pages: ${{ github.event_name == 'push' }}
benchmark-data-dir-path: ./cache/benchmarks
ref: "ec5b182e486543fb2810419377774b9957a3d3ee"

docs:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down
14 changes: 12 additions & 2 deletions examples/grid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ async function run(metrics?: IMetrics) {
});

const button_connect = <HTMLButtonElement>document.getElementById("joinGrid");
const grid_input = <HTMLInputElement>document.getElementById("gridInput");
grid_input.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
button_connect.click();
}
});
button_connect.addEventListener("click", async () => {
const drpId = (<HTMLInputElement>document.getElementById("gridInput")).value;
const drpId = grid_input.value;
try {
gridState.drpObject = await gridState.node.connectObject({
id: drpId,
Expand Down Expand Up @@ -138,15 +144,19 @@ async function main() {
metrics = new OpentelemetryMetrics("grid-service-2");
}

let hasRun = false;

const networkConfig = getNetworkConfigFromEnv();
gridState.node = new DRPNode(networkConfig ? { network_config: networkConfig } : undefined);
await gridState.node.start();
await gridState.node.networkNode.isDialable(async () => {
console.log("Started node", import.meta.env);
if (hasRun) return;
hasRun = true;
await run(metrics);
});

setInterval(renderInfo, import.meta.env.VITE_RENDER_INFO_INTERVAL);
if (!hasRun) setInterval(renderInfo, import.meta.env.VITE_RENDER_INFO_INTERVAL);
}

void main();
Empty file added test
Empty file.

0 comments on commit ff7a5b4

Please sign in to comment.