Skip to content

Commit

Permalink
Merge pull request #1101 from neet/remove-unneeded-signal-merging
Browse files Browse the repository at this point in the history
fix: Remove unnecessary merging of AbortSignal to avoid overhead
  • Loading branch information
neet authored Apr 27, 2024
2 parents bbfb99d + 8967643 commit f45f165
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/adapters/config/http-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export interface MastoHttpConfigProps {
readonly accessToken?: string;

/**
* Timeout configuration
* Timeout milliseconds for the fetch request.
*
* - A number sets the timeout in milliseconds.
*
* Defaults to 1000 * 300 = 300 seconds.
* Defaults to browser's default timeout.
*/
readonly timeout?: number;

Expand Down Expand Up @@ -95,6 +93,6 @@ export class HttpConfigImpl implements HttpConfig {
signals.push(signal);
}

return mergeAbortSignals(signals);
return signals.length === 1 ? signals[0] : mergeAbortSignals(signals);
}
}
3 changes: 2 additions & 1 deletion src/adapters/http/http-native-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ export class HttpNativeImpl extends BaseHttp implements Http {
);
}

// TODO: Remove this handling when `AbortSignal.any` is shipped
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (error != undefined && (error as any).name === "AbortError") {
if (error != undefined && (error as any).name === "TimeoutError") {
return new MastoTimeoutError(`Request timed out`, { cause: error });
}

Expand Down

0 comments on commit f45f165

Please sign in to comment.