Skip to content

Commit

Permalink
fix(rpc): abort-controller is not a constructor in browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
homura committed Dec 11, 2023
1 parent 1dd7cac commit 1ad36d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "./exceptions";
import { RPCConfig } from "./types/common";
import fetch_ from "cross-fetch";
import { AbortController as CrossAbortController } from "abort-controller";
import AbortController from "abort-controller";

export const ParamsFormatter = paramsFormatter;
export const ResultFormatter = resultFormatter;
Expand Down Expand Up @@ -134,8 +134,8 @@ export class CKBRPC extends Base {
}
});

const controller = new CrossAbortController() as AbortController;
const signal = controller.signal;
const controller = new AbortController();
const signal = controller.signal as AbortSignal;

const timeout = setTimeout(
() => controller.abort(),
Expand All @@ -147,7 +147,7 @@ export class CKBRPC extends Base {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(payload),
signal: signal,
signal,
})
.then((res) => res.json());

Expand Down
6 changes: 3 additions & 3 deletions packages/rpc/src/method.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IdNotMatchException, ResponseException } from "./exceptions";
import { CKBComponents } from "./types/api";
import { RPCConfig } from "./types/common";
import { AbortController as CrossAbortController } from "abort-controller";
import AbortController from "abort-controller";
import fetch_ from "cross-fetch";

export class Method {
Expand Down Expand Up @@ -42,8 +42,8 @@ export class Method {
/* eslint-disable @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types */
public call = async (...params: (string | number | object)[]) => {
const payload = this.getPayload(...params);
const controller = new CrossAbortController() as AbortController;
const signal = controller.signal;
const controller = new AbortController();
const signal = controller.signal as AbortSignal;

const timeout = setTimeout(() => controller.abort(), this.#config.timeout);

Expand Down

0 comments on commit 1ad36d5

Please sign in to comment.