Skip to content

Commit 7d02f3b

Browse files
committed
refactor: process queued commands in parallel instead of sequentially.
1 parent 0e36ec0 commit 7d02f3b

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/services/universeBackendBridge.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,31 +136,33 @@ class UniverseBackendBridge {
136136
}
137137

138138
async processQueuedCommands() {
139-
console.log(`[UniverseBackendBridge] Processing ${this.commandQueue.length} queued commands`);
140-
141139
if (this.useDirectBackend) {
142-
while (this.commandQueue.length > 0) {
143-
const queuedCommand = this.commandQueue.shift();
140+
const pending = this.commandQueue.splice(0, this.commandQueue.length);
141+
// Execute in parallel but handle errors individually
142+
pending.forEach(async (queuedCommand) => {
144143
try {
145144
const result = await this.executeDirectCommand(queuedCommand.command, queuedCommand.payload);
146145
queuedCommand.resolve(result);
147146
} catch (error) {
148147
console.error('[UniverseBackendBridge] Queued command failed during direct fallback:', error);
149148
queuedCommand.reject(error);
150149
}
151-
}
150+
});
152151
return;
153152
}
154153

155-
while (this.commandQueue.length > 0) {
156-
const queuedCommand = this.commandQueue.shift();
154+
const pending = this.commandQueue.splice(0, this.commandQueue.length);
155+
// Execute all queued commands in parallel
156+
// We don't await the results here because each command handles its own resolution/rejection
157+
// and we don't want one slow command to block others.
158+
pending.forEach(async (queuedCommand) => {
157159
try {
158160
await this.executeCommand(queuedCommand);
159161
} catch (error) {
160162
console.error('[UniverseBackendBridge] Queued command failed:', error);
161163
queuedCommand.reject(error);
162164
}
163-
}
165+
});
164166
}
165167

166168
async executeCommand({ command, payload, id, resolve, reject }) {

0 commit comments

Comments
 (0)