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

fix!: cancel _checkInternetReachability request on timeout & cancel via AbortController #678

Merged
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions src/internal/internetReachability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,23 @@
};

private _checkInternetReachability = (): InternetReachabilityCheckHandler => {
const controller = new AbortController();

const responsePromise = fetch(this._configuration.reachabilityUrl, {
method: this._configuration.reachabilityMethod,
cache: 'no-cache',
signal: controller.signal,
});

// 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(

Check failure on line 83 in src/internal/internetReachability.ts

View workflow job for this annotation

GitHub Actions / test

Delete `⏎··········`
(): void => reject('timedout'),
(): void => {
controller.abort();

Check failure on line 85 in src/internal/internetReachability.ts

View workflow job for this annotation

GitHub Actions / test

Delete `··`
reject('timedout');

Check failure on line 86 in src/internal/internetReachability.ts

View workflow job for this annotation

GitHub Actions / test

Delete `··`
},

Check failure on line 87 in src/internal/internetReachability.ts

View workflow job for this annotation

GitHub Actions / test

Replace `··},⏎··········this._configuration.reachabilityRequestTimeout,⏎········` with `},·this._configuration.reachabilityRequestTimeout`
this._configuration.reachabilityRequestTimeout,
);
},
Expand All @@ -89,7 +95,10 @@
let cancel: () => void = (): void => {};
const cancelPromise = new Promise<Response>(
(_, reject): void => {
cancel = (): void => reject('canceled');
cancel = (): void => {
controller.abort();
reject('canceled');
};
},
);

Expand Down