mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
36 lines
776 B
JavaScript
36 lines
776 B
JavaScript
/**
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
/**
|
|
* Creates a cancelable axios 'request object'.
|
|
*
|
|
* @param {Function} request the axios promise request
|
|
* @return {object}
|
|
*/
|
|
function cancelableRequest(request) {
|
|
const controller = new AbortController()
|
|
const signal = controller.signal
|
|
|
|
/**
|
|
* Execute the request
|
|
*
|
|
* @param {string} url the url to send the request to
|
|
* @param {object} [options] optional config for the request
|
|
*/
|
|
const fetch = async function(url, options) {
|
|
const response = await request(
|
|
url,
|
|
{ signal, ...options },
|
|
)
|
|
return response
|
|
}
|
|
|
|
return {
|
|
request: fetch,
|
|
abort: () => controller.abort(),
|
|
}
|
|
}
|
|
|
|
export default cancelableRequest
|