nextcloud/apps/comments/src/utils/cancelableRequest.js
Ferdinand Thiessen 691f570237
chore: Enable ESLint for apps and fix all errors
Nevertheless this causes a huge amount of new warnings.
Previously the shell script for directories to lint was wrong it was generating all app names to lint,
but was missing the `apps/` prefix. Causing only `core` to be linted.

Co-authored-by: Grigorii K. Shartsev <me@shgk.me>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2024-07-09 17:13:30 +02:00

36 lines
796 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}
*/
const cancelableRequest = function(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,
Object.assign({ signal }, options),
)
return response
}
return {
request: fetch,
abort: () => controller.abort(),
}
}
export default cancelableRequest