Skip to content

Commit

Permalink
Merge pull request #1250 from nextcloud/backport/1247/stable23
Browse files Browse the repository at this point in the history
[stable23] Use modern API to cancel requests
  • Loading branch information
blizzz authored May 20, 2022
2 parents 3fa859e + 2478dc7 commit a78c2b4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
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 @@ -183,6 +183,7 @@ object-assign
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Louis Chemineau <louis@chmn.me>
*
* @license GNU AGPL version 3 or any later version
*
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 <marcoambrosini@pm.me>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Louis Chemineau <louis@chmn.me>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -21,20 +22,14 @@
*
*/

import axios from '@nextcloud/axios'

/**
* Creates a cancelable axios 'request object'.
*
* @param {function} request the axios promise request
* @returns {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

0 comments on commit a78c2b4

Please sign in to comment.