MCPcopy
hub / github.com/vercel/next.js / prime

Function prime

test/e2e/cancel-request/stream-cancel.test.ts:10–46  ·  view source on GitHub ↗
(url: string, noData?: boolean)

Source from the content-addressed store, hash-verified

8 })
9
10 function prime(url: string, noData?: boolean) {
11 return new Promise<void>((resolve, reject) => {
12 url = new URL(url, next.url).href
13
14 // There's a bug in node-fetch v2 where aborting the fetch will never abort
15 // the connection, because the body is a transformed stream that doesn't
16 // close the connection stream.
17 // https://github.com/node-fetch/node-fetch/pull/670
18 const req = get(url, async (res) => {
19 while (true) {
20 const value = res.read(1)
21 if (value) break
22 await sleep(5)
23 }
24
25 res.destroy()
26 resolve()
27 })
28 req.on('error', reject)
29 req.end()
30
31 if (noData) {
32 req.on('error', (e) => {
33 // Swallow the "socket hang up" message that happens if you abort
34 // before the a response connection is received.
35 if ((e as any).code !== 'ECONNRESET') {
36 throw e
37 }
38 })
39
40 setTimeout(() => {
41 req.abort()
42 resolve()
43 }, 100)
44 }
45 })
46 }
47
48 describe.each([
49 ['middleware', '/middleware'],

Callers 1

Calls 9

sleepFunction · 0.90
readMethod · 0.65
endMethod · 0.65
getFunction · 0.50
resolveFunction · 0.50
setTimeoutFunction · 0.50
destroyMethod · 0.45
onMethod · 0.45
abortMethod · 0.45

Tested by

no test coverage detected