Skip to content

Commit

Permalink
feat: add toAbortSignal to UnCancelToken, axios#6582
Browse files Browse the repository at this point in the history
  • Loading branch information
ModyQyW committed Sep 2, 2024
1 parent 43b5bc5 commit 738486c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 92 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@dcloudio/types": "^3.4.12",
"@lerna-lite/cli": "^3.8.0",
"@lerna-lite/version": "^3.8.0",
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/core/UnCancelToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ export class UnCancelToken<T = UnData, D = UnData> {
}
}

toAbortSignal() {
const controller = new AbortController();

const abort: UnCancelTokenListener = (error) => {
controller.abort(error);
};

this.subscribe(abort);

// @ts-expect-error Property 'unsubscribe' does not exist on type 'AbortSignal'.ts(2339)
controller.signal.unsubscribe = () => this.unsubscribe(abort);

return controller.signal as AbortSignal & {
unsubscribe: () => void;
};
}

static source<TT = UnData, DD = UnData>(): UnCancelTokenSource<TT, DD> {
let cancel: UnCanceler<TT, DD>;
const token = new UnCancelToken<TT, DD>((c) => {
Expand Down
91 changes: 0 additions & 91 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 738486c

Please sign in to comment.