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

Only use AbortSignal.timeout if it exists #197

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fauna",
"version": "1.0.0",
"version": "1.0.1",
"description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes",
"homepage": "https://fauna.com",
"bugs": {
Expand Down
12 changes: 11 additions & 1 deletion src/http-client/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ export class FetchClient implements HTTPClient {
method,
client_timeout_ms,
}: HTTPRequest): Promise<HTTPResponse> {
const signal =
AbortSignal.timeout === undefined
? (() => {
const controller = new AbortController();
const signal = controller.signal;
setTimeout(() => controller.abort(), client_timeout_ms);
return signal;
})()
: AbortSignal.timeout(client_timeout_ms);

const response = await fetch(this.#url, {
method,
headers: { ...requestHeaders, "Content-Type": "application/json" },
body: JSON.stringify(data),
signal: AbortSignal.timeout(client_timeout_ms),
signal,
keepalive: this.#keepalive,
}).catch((error) => {
throw new NetworkError("The network connection encountered a problem.", {
Expand Down
2 changes: 1 addition & 1 deletion src/util/package-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//THIS FILE IS AUTOGENERATED. DO NOT EDIT. SEE .husky/pre-commit

/** The current package version. */
export const packageVersion = "1.0.0";
export const packageVersion = "1.0.1";