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

Method enqueue

packages/next/src/client/components/promise-queue.ts:21–49  ·  view source on GitHub ↗
(promiseFn: () => Promise<T>)

Source from the content-addressed store, hash-verified

19 }
20
21 enqueue<T>(promiseFn: () => Promise<T>): Promise<T> {
22 let taskResolve: (value: T | PromiseLike<T>) => void
23 let taskReject: (reason?: any) => void
24
25 const taskPromise = new Promise((resolve, reject) => {
26 taskResolve = resolve
27 taskReject = reject
28 }) as Promise<T>
29
30 const task = async () => {
31 try {
32 this.#runningCount++
33 const result = await promiseFn()
34 taskResolve(result)
35 } catch (error) {
36 taskReject(error)
37 } finally {
38 this.#runningCount--
39 this.#processNext()
40 }
41 }
42
43 const enqueueResult = { promiseFn: taskPromise, task }
44 // wonder if we should take a LIFO approach here
45 this.#queue.push(enqueueResult)
46 this.#processNext()
47
48 return taskPromise
49 }
50
51 bump(promiseFn: Promise<any>) {
52 const index = this.#queue.findIndex((item) => item.promiseFn === promiseFn)

Callers 9

nextServerDataCallbackFunction · 0.45
pullFunction · 0.45
startFunction · 0.45
pullFunction · 0.45
startFunction · 0.45
transformFunction · 0.45
startFunction · 0.45

Calls 2

#processNextMethod · 0.95
pushMethod · 0.65

Tested by

no test coverage detected