(
url: string,
options: RequestInit = {}
)
| 369 | * @returns { abort, promise } - abort 函数和 promise |
| 370 | */ |
| 371 | export function cancellableFetch<T>( |
| 372 | url: string, |
| 373 | options: RequestInit = {} |
| 374 | ): { abort: () => void; promise: Promise<T> } { |
| 375 | const controller = new AbortController() |
| 376 | const promise = fetchWithTimeout<T>(url, { |
| 377 | ...options, |
| 378 | signal: controller.signal, |
| 379 | }) |
| 380 | |
| 381 | return { |
| 382 | abort: () => controller.abort(), |
| 383 | promise, |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * 并发请求控制器 |
nothing calls this directly
no test coverage detected