Skip to content

Commit

Permalink
Don't throw during for await
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorhansen committed Sep 6, 2023
1 parent e556acb commit 7e635e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ts/battle/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,19 @@ class BattleWorker {
for await (const [msg] of this.battleSock) {
const req = JSON.parse(msg.toString()) as BattleRequest;
if (req.type !== "battle") {
throw new Error(`Unknown request type '${req.type}'`);
console.error(
`${this.workerId}: Unknown request type '${req.type}' ` +
`(id=${req.id})`,
);
continue;
}

// Since the simulator is very efficient compared to the number
// crunching required by the model agents (which can batch multiple
// requests for the same agent), we allow this single-threaded Node
// server to run many battles "in parallel" (asynchronously).
// As for how many parallel/async battles should be allowed, load
// balancing/etc is handled by the sender.
// We don't limit the amount of async-parallel battles here, instead
// relying on how the sender uses this worker.
const battlePromise = this.dispatchBattle(req).catch(e =>
console.error(
`${this.workerId}:`,
Expand Down

0 comments on commit 7e635e1

Please sign in to comment.