MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / abortableFetch

Function abortableFetch

src/services/utils/http.test.ts:125–137  ·  view source on GitHub ↗
(captured: { signal?: AbortSignal | null })

Source from the content-addressed store, hash-verified

123 describe('analytics request cancellation', () => {
124 // 模拟真实 fetch:捕获 signal,并在 abort 时以 AbortError 拒绝(其余保持 pending)。
125 function abortableFetch(captured: { signal?: AbortSignal | null }) {
126 return ((_input: unknown, init?: RequestInit) => {
127 captured.signal = init?.signal
128 return new Promise<Response>((_resolve, reject) => {
129 const signal = init?.signal
130 if (signal?.aborted) {
131 reject(new DOMException('Aborted', 'AbortError'))
132 return
133 }
134 signal?.addEventListener('abort', () => reject(new DOMException('Aborted', 'AbortError')))
135 })
136 }) as typeof fetch
137 }
138
139 it('passes a non-aborted signal and abortAnalyticsRequests() cancels the in-flight request', async () => {
140 const originalFetch = globalThis.fetch

Callers 1

http.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected