Skip to content

Commit d8e4c6f

Browse files
authored
perf: do hibernation and shutdown in parallel (#54)
1 parent b7d19ae commit d8e4c6f

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

src/bin/commands/sandbox/hibernate.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,28 @@ export async function hibernateSandbox(id?: string) {
6464
let failCount = 0;
6565
const results: CommandResult[] = [];
6666

67-
for (const sandboxId of ids) {
68-
try {
69-
const result = await hibernateSingleSandbox(sandboxId, null as any);
70-
results.push(result);
71-
if (result.success) {
72-
successCount++;
73-
} else {
67+
// Run all hibernations in parallel
68+
const hibernatePromises = ids.map((sandboxId) =>
69+
hibernateSingleSandbox(sandboxId, null as any)
70+
.then((result) => {
71+
results.push(result);
72+
if (result.success) {
73+
successCount++;
74+
} else {
75+
failCount++;
76+
}
77+
return result;
78+
})
79+
.catch(() => {
7480
failCount++;
75-
}
76-
} catch (error) {
77-
failCount++;
78-
}
79-
}
81+
return {
82+
success: false,
83+
message: `Failed to hibernate sandbox ${sandboxId}`,
84+
};
85+
})
86+
);
87+
88+
await Promise.all(hibernatePromises);
8089

8190
// Final summary
8291
if (failCount === 0) {

src/bin/commands/sandbox/shutdown.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,28 @@ export async function shutdownSandbox(id?: string) {
6464
let failCount = 0;
6565
const results: CommandResult[] = [];
6666

67-
for (const sandboxId of ids) {
68-
try {
69-
const result = await shutdownSingleSandbox(sandboxId, null as any);
70-
results.push(result);
71-
if (result.success) {
72-
successCount++;
73-
} else {
67+
// Run all shutdowns in parallel
68+
const shutdownPromises = ids.map((sandboxId) =>
69+
shutdownSingleSandbox(sandboxId, null as any)
70+
.then((result) => {
71+
results.push(result);
72+
if (result.success) {
73+
successCount++;
74+
} else {
75+
failCount++;
76+
}
77+
return result;
78+
})
79+
.catch(() => {
7480
failCount++;
75-
}
76-
} catch (error) {
77-
failCount++;
78-
}
79-
}
81+
return {
82+
success: false,
83+
message: `Failed to shutdown sandbox ${sandboxId}`,
84+
};
85+
})
86+
);
87+
88+
await Promise.all(shutdownPromises);
8089

8190
// Final summary
8291
if (failCount === 0) {

0 commit comments

Comments
 (0)