UNPKG

appwrite-utils-cli

Version:

Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.

28 lines (24 loc) 817 B
import type { Models } from "node-appwrite"; export const retryFailedPromises = async ( batch: Promise<Models.Document>[], maxRetries = 3 ): Promise<PromiseSettledResult<Models.Document>[]> => { const results = await Promise.allSettled(batch); const toRetry: Promise<any>[] = []; results.forEach((result, index) => { if (result.status === "rejected") { console.error("Promise rejected with reason:", result.reason); if (maxRetries > 0) { toRetry.push(batch[index]); } } }); if (toRetry.length > 0) { console.log(`Retrying ${toRetry.length} promises`); return retryFailedPromises(toRetry, maxRetries - 1); } else { return results .filter((result) => result.status === "fulfilled") .map((result) => result); } };