Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed abort pending request of internetReachability #700

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/internal/internetReachability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,19 @@ export default class InternetReachability {

// Create promise that will reject after the request timeout has been reached
let timeoutHandle: ReturnType<typeof setTimeout>;
const timeoutPromise = new Promise<Response>(
(_, reject): void => {
timeoutHandle = setTimeout((): void => {
controller.abort();
reject('timedout');
}, this._configuration.reachabilityRequestTimeout);
},
);
const timeoutPromise = new Promise<Response>((): void => {
timeoutHandle = setTimeout(
(): void => controller.abort('timedout'),
this._configuration.reachabilityRequestTimeout,
);
});

// Create promise that makes it possible to cancel a pending request through a reject
// eslint-disable-next-line @typescript-eslint/no-empty-function
let cancel: () => void = (): void => {};
const cancelPromise = new Promise<Response>(
(_, reject): void => {
cancel = (): void => {
controller.abort();
reject('canceled');
};
},
);
const cancelPromise = new Promise<Response>((): void => {
cancel = (): void => controller.abort('canceled');
});

const promise = Promise.race([
responsePromise,
Expand Down