Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
[Lib > Plugins] Use our own allSettled
Browse files Browse the repository at this point in the history
  • Loading branch information
redstonekasi authored and maisymoe committed Oct 20, 2023
1 parent 43d351c commit d602f60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PluginManifest, Plugin } from "@types";
import { safeFetch } from "@lib/utils";
import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
import { MMKVManager } from "@lib/native";
import { allSettled } from "@lib/polyfills";
import logger, { logModule } from "@lib/logger";
import settings from "@lib/settings";

Expand Down Expand Up @@ -131,7 +132,7 @@ export async function initPlugins() {

if (!settings.safeMode?.enabled) {
// Loop over any plugin that is enabled, update it if allowed, then start it.
await Promise.allSettled(allIds.filter(pl => plugins[pl].enabled).map(async (pl) => (plugins[pl].update && await fetchPlugin(pl).catch((e: Error) => logger.error(e.message)), await startPlugin(pl))));
await allSettled(allIds.filter(pl => plugins[pl].enabled).map(async (pl) => (plugins[pl].update && await fetchPlugin(pl).catch((e: Error) => logger.error(e.message)), await startPlugin(pl))));
// Wait for the above to finish, then update all disabled plugins that are allowed to.
allIds.filter(pl => !plugins[pl].enabled && plugins[pl].update).forEach(pl => fetchPlugin(pl));
};
Expand Down
5 changes: 5 additions & 0 deletions src/lib/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Starting from 202.4, Promise.allSettled may be undefined due to conflicting then/promise versions, so we use our own.
const allSettledFulfill = <T>(value: T) => ({ status: "fulfilled", value });
const allSettledReject = <T>(reason: T) => ({ status: "rejected", reason });
const mapAllSettled = <T>(item: T) => Promise.resolve(item).then(allSettledFulfill, allSettledReject);
export const allSettled = <T extends unknown[]>(iterator: T) => Promise.all(Array.from(iterator).map(mapAllSettled));

0 comments on commit d602f60

Please sign in to comment.