Skip to content

Commit 738486c

Browse files
committed
feat: add toAbortSignal to UnCancelToken, axios#6582
1 parent 43b5bc5 commit 738486c

File tree

3 files changed

+17
-92
lines changed

3 files changed

+17
-92
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"type-check": "tsc --noEmit"
5252
},
5353
"devDependencies": {
54-
"@biomejs/biome": "^1.8.3",
5554
"@dcloudio/types": "^3.4.12",
5655
"@lerna-lite/cli": "^3.8.0",
5756
"@lerna-lite/version": "^3.8.0",

packages/core/src/core/UnCancelToken.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ export class UnCancelToken<T = UnData, D = UnData> {
9696
}
9797
}
9898

99+
toAbortSignal() {
100+
const controller = new AbortController();
101+
102+
const abort: UnCancelTokenListener = (error) => {
103+
controller.abort(error);
104+
};
105+
106+
this.subscribe(abort);
107+
108+
// @ts-expect-error Property 'unsubscribe' does not exist on type 'AbortSignal'.ts(2339)
109+
controller.signal.unsubscribe = () => this.unsubscribe(abort);
110+
111+
return controller.signal as AbortSignal & {
112+
unsubscribe: () => void;
113+
};
114+
}
115+
99116
static source<TT = UnData, DD = UnData>(): UnCancelTokenSource<TT, DD> {
100117
let cancel: UnCanceler<TT, DD>;
101118
const token = new UnCancelToken<TT, DD>((c) => {

pnpm-lock.yaml

Lines changed: 0 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)