nextcloud/apps/comments/src/utils/cancelableRequest.js
Ferdinand Thiessen 91f3b6b4ee
chore: adjust code to new codestyle
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2025-10-02 13:19:42 +02:00

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