Skip to content

Commit

Permalink
Only use AbortSignal.timeout if it exists (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleve-fauna authored Aug 21, 2023
1 parent e4eb87a commit 819b1c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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";

0 comments on commit 819b1c3

Please sign in to comment.