-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Fixed cancelToken leakage; Added AbortController support; #3305
Fixed cancelToken leakage; Added AbortController support; #3305
Conversation
Added AbortController support;
…cancel-token-leak
…el-token-leak � Conflicts: � package.json
…sending a request;
Any updates about feature integration in master branch ? It seems to be a very useful feature for me. |
Just for testing purposes, you can play around with this and some other PRs in this sandbox; |
…el-token-leak � Conflicts: � index.d.ts � lib/adapters/xhr.js
…cancel-token-leak
…el-token-leak � Conflicts: � README.md
any blockers? It would be nice to have that support without breaking changes. |
@jasonsaayman Is there any chance that this PR will be reviewed? :) |
@jasonsaayman I would love to see this in too |
Im migrating our Web applications api client from fetch to axios and we have consumers passing |
Would like to see this merged too. |
Would love this one to get in! |
The proposal for |
… fix/cancel-token-leak
…cancel-token-leak
@jasonsaayman rebased this on 0.22.0 just in case ;) |
* fix/Avoid package.json import; (#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <[email protected]> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <[email protected]> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <[email protected]>
* fix/Avoid package.json import; (#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <[email protected]> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <[email protected]> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <[email protected]>
* fix/Avoid package.json import; (axios#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (axios#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (axios#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <[email protected]> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (axios#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <[email protected]> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <[email protected]>
* fix/Avoid package.json import; (axios#4041) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Feat/export package version constant (axios#4065) * Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`; Refactored `http.js` to use `env/data.js` instead of package.json; * Added `env/data.js`; Added `env/README.md`; * Export package version constant; * Fixed cancelToken leakage; Added AbortController support; (axios#3305) * Fixed cancelToken leakage; Added AbortController support; * Fixed typings; * Documented `signal` option; * Added processing of early cancellation using AbortController without sending a request; Co-authored-by: Jay <[email protected]> * Updating CI to run on release branches * Fixed default transitional config for custom Axios instance; (axios#4052) Refactored `/core/mergeConfig`; Co-authored-by: Jay <[email protected]> * Prepping v0.22.0 for release * Updated date Co-authored-by: Dmitriy Mozgovoy <[email protected]>
The type signatures don't match on [email protected] and [email protected], also doesn't match on [email protected] The workaround is to cast it as
|
this.promise.then = function(onfulfilled) { | ||
var _resolve; | ||
// eslint-disable-next-line func-names | ||
var promise = new Promise(function(resolve) { | ||
token.subscribe(resolve); | ||
_resolve = resolve; | ||
}).then(onfulfilled); | ||
|
||
promise.cancel = function reject() { | ||
token.unsubscribe(_resolve); | ||
}; | ||
|
||
return promise; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you had removed code "config.cancelToken.promise.then(function onCanceled(cancel) " from the file named "adapter/xhr.js" in this commit, I think lines 38~52 are no longer needed.
I try to remove lines 38~52 here and then run the script "npm run test", finally find out that all tests are passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but CancelToken is a public interface, so we can't be sure that user code is somehow not relying on its thenable/promise interface. IMHO, this should be kept as long as the CancelToken exists in the codebase.
This PR fixes
cancelToken
and adds an alternative way to cancel Axios request withAbortController
.AbortController
support. I believe that using the existing API makes it easier to use the library.CancelToken
andAbortController
can be used simultaneously (to facilitate the transition to the new API)Recently published as
axios-lab
npm forkLive demo