Skip to content

Commit

Permalink
use promise settled
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Nov 8, 2024
1 parent e22656a commit 3a0da72
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/migrations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export async function executeMigrations(
signer: Signer,
mevBoost: MevBoost
): Promise<void> {
const migrationErrors = [];

const migrations = [
{
fn: removeLegacyDockerAssets,
Expand Down Expand Up @@ -90,13 +88,15 @@ export async function executeMigrations(
}
];

for (const { fn, migration, coreVersion } of migrations) {
try {
await fn();
} catch (e) {
migrationErrors.push(new Error(`Migration ${migration} (${coreVersion}) failed: ${e.message}`));
}
}
const migrationPromises = migrations.map(({ fn, migration, coreVersion }) =>
fn().catch((e) => new Error(`Migration ${migration} (${coreVersion}) failed: ${e.message}`))
);

// Run all migrations concurrently and wait for all to settle
const results = await Promise.allSettled(migrationPromises);

// Collect any errors
const migrationErrors = results.filter((result) => result.status === "rejected").map((result) => result.reason);

if (migrationErrors.length > 0) {
throw new AggregateError(migrationErrors, "One or more migrations failed");
Expand Down

0 comments on commit 3a0da72

Please sign in to comment.