Skip to content
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

[stable24] Use modern API to cancel requests #1249

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/viewer-main.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ object-assign
*
* @author Marco Ambrosini <[email protected]>
* @author John Molakvoæ <[email protected]>
* @author Louis Chemineau <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down
2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions src/utils/CancelableRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* @author Marco Ambrosini <[email protected]>
* @author John Molakvoæ <[email protected]>
* @author Louis Chemineau <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand All @@ -21,20 +22,14 @@
*
*/

import axios from '@nextcloud/axios'

/**
* Creates a cancelable axios 'request object'.
*
* @param {Function} request the axios promise request
* @return {object}
*/
const CancelableRequest = function(request) {
/**
* Generate an axios cancel token
*/
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const controller = new AbortController()

/**
* Execute the request
Expand All @@ -45,12 +40,12 @@ const CancelableRequest = function(request) {
const fetch = async function(url, options) {
return request(
url,
Object.assign({ cancelToken: source.token }, { options })
{ ...options, signal: controller.signal }
)
}
return {
request: fetch,
cancel: source.cancel,
cancel: () => controller.abort(),
}
}

Expand Down