[Lib > Plugins] Use our own allSettled
This commit is contained in:
parent
43d351ce4f
commit
d602f60a96
2 changed files with 7 additions and 1 deletions
|
@ -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";
|
||||
|
||||
|
@ -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));
|
||||
};
|
||||
|
|
5
src/lib/polyfills.ts
Normal file
5
src/lib/polyfills.ts
Normal file
|
@ -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));
|
Loading…
Reference in a new issue