Revert "fix: harden automatic mobile boards"
This reverts commit d0b9348b86.
This commit is contained in:
1 parent
92a2be2b65
commit
dba9a250ff
37 files changed
+137
-637
No files matched your search
@@ -11,24 +11,13 @@ interface IntegrationLike {
|
||||
|
||||
interface Options<TIntegration extends IntegrationLike, TResult> {
|
||||
fallback?: (integration: TIntegration, error: unknown) => TResult;
|
||||
throwOnAllFailure?: boolean;
|
||||
}
|
||||
|
||||
export interface IntegrationQueryProvenance {
|
||||
failedIntegrationCount: number;
|
||||
staleIntegrationCount: number;
|
||||
}
|
||||
|
||||
interface IntegrationQuerySettlement<TResult> {
|
||||
results: TResult[];
|
||||
failedIntegrationCount: number;
|
||||
}
|
||||
|
||||
const settleIntegrationQueriesInternal = async <TIntegration extends IntegrationLike, TResult>(
|
||||
export async function settleIntegrationQueries<TIntegration extends IntegrationLike, TResult>(
|
||||
integrations: TIntegration[],
|
||||
fn: (integration: TIntegration) => Promise<TResult>,
|
||||
options?: Options<TIntegration, TResult>,
|
||||
): Promise<IntegrationQuerySettlement<TResult>> => {
|
||||
): Promise<TResult[]> {
|
||||
const settled = await Promise.allSettled(integrations.map(async (integration) => fn(integration)));
|
||||
const results: TResult[] = [];
|
||||
const errors: unknown[] = [];
|
||||
@@ -56,46 +45,9 @@ const settleIntegrationQueriesInternal = async <TIntegration extends Integration
|
||||
errors.push(result.reason);
|
||||
});
|
||||
|
||||
const firstFailure = settled.find((result) => result.status === "rejected");
|
||||
if (
|
||||
options?.throwOnAllFailure === true &&
|
||||
settled.length > 0 &&
|
||||
settled.every((result) => result.status === "rejected") &&
|
||||
firstFailure?.status === "rejected"
|
||||
) {
|
||||
throw firstFailure.reason;
|
||||
}
|
||||
|
||||
if (options?.throwOnAllFailure !== false && results.length === 0 && errors.length > 0) {
|
||||
if (results.length === 0 && errors.length > 0) {
|
||||
throw errors[0];
|
||||
}
|
||||
|
||||
return {
|
||||
results,
|
||||
failedIntegrationCount: settled.filter((result) => result.status === "rejected").length,
|
||||
};
|
||||
};
|
||||
|
||||
export async function settleIntegrationQueries<TIntegration extends IntegrationLike, TResult>(
|
||||
integrations: TIntegration[],
|
||||
fn: (integration: TIntegration) => Promise<TResult>,
|
||||
options?: Options<TIntegration, TResult>,
|
||||
): Promise<TResult[]> {
|
||||
return (await settleIntegrationQueriesInternal(integrations, fn, options)).results;
|
||||
}
|
||||
|
||||
export async function settleIntegrationQueriesWithProvenance<
|
||||
TIntegration extends IntegrationLike,
|
||||
TResult extends { isStale?: boolean },
|
||||
>(
|
||||
integrations: TIntegration[],
|
||||
fn: (integration: TIntegration) => Promise<TResult>,
|
||||
options?: Options<TIntegration, TResult>,
|
||||
): Promise<IntegrationQuerySettlement<TResult> & IntegrationQueryProvenance> {
|
||||
const settlement = await settleIntegrationQueriesInternal(integrations, fn, options);
|
||||
|
||||
return {
|
||||
...settlement,
|
||||
staleIntegrationCount: settlement.results.filter((result) => result.isStale === true).length,
|
||||
};
|
||||
return results;
|
||||
}
|
||||
Reference in new issue
Block a user