| 2393 | |
| 2394 | async process<T>( |
| 2395 | input: T, |
| 2396 | next: (input: T, token?: AbortToken) => Promise<any>, |
| 2397 | token?: AbortToken, |
| 2398 | ): Promise<any> { |
| 2399 | const config = (await this.configManagerPromise).getConfig(); |
| 2400 | const timeoutMs = config.timeout * 1000; |
| 2401 | |
| 2402 | const timeoutController = new AbortController(); |
| 2403 | const timeoutId = setTimeout( |
| 2404 | () => timeoutController.abort(`请求超时: ${timeoutMs}ms`), |
| 2405 | timeoutMs, |
| 2406 | ); |
| 2407 | |
| 2408 | try { |
| 2409 | const combined = this.combine(timeoutController, token); |
| 2410 | combined.signal.addEventListener("abort", () => clearTimeout(timeoutId), { |
| 2411 | once: true, |
| 2412 | }); |
| 2413 | return await next(input, combined); |
| 2414 | } finally { |
| 2415 | clearTimeout(timeoutId); |
| 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | private combine( |
| 2420 | timeoutController: AbortController, |
| 2421 | externalToken?: AbortToken, |