nextcloud/apps/comments/src/utils/cancelableRequest.ts
Ferdinand Thiessen e26588d78c chore: fix ESLint errors
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-04-01 14:54:43 +02:00

36 lines
842 B
TypeScript

/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* Creates a cancelable axios 'request object'.
*
* @param request the axios promise request
* @return
*/
function cancelableRequest(request: (url: string, options?: Record<string, unknown>) => Promise<unknown>) {
const controller = new AbortController()
const signal = controller.signal
/**
* Execute the request
*
* @param url the url to send the request to
* @param [options] optional config for the request
*/
const fetch = async function(url: string, options?: Record<string, unknown>) {
const response = await request(
url,
{ signal, ...options },
)
return response
}
return {
request: fetch,
abort: () => controller.abort(),
}
}
export default cancelableRequest