MCPcopy Index your code
hub / github.com/codeaashu/claude-code / sequential

Function sequential

src/utils/sequential.ts:19–56  ·  view source on GitHub ↗
(
  fn: (...args: T) => Promise<R>,
)

Source from the content-addressed store, hash-verified

17 * @returns A wrapped version of the function that executes calls sequentially
18 */
19export function sequential<T extends unknown[], R>(
20 fn: (...args: T) => Promise<R>,
21): (...args: T) => Promise<R> {
22 const queue: QueueItem<T, R>[] = []
23 let processing = false
24
25 async function processQueue(): Promise<void> {
26 if (processing) return
27 if (queue.length === 0) return
28
29 processing = true
30
31 while (queue.length > 0) {
32 const { args, resolve, reject, context } = queue.shift()!
33
34 try {
35 const result = await fn.apply(context, args)
36 resolve(result)
37 } catch (error) {
38 reject(error)
39 }
40 }
41
42 processing = false
43
44 // Check if new items were added while we were processing
45 if (queue.length > 0) {
46 void processQueue()
47 }
48 }
49
50 return function (this: unknown, ...args: T): Promise<R> {
51 return new Promise((resolve, reject) => {
52 queue.push({ args, resolve, reject, context: this })
53 void processQueue()
54 })
55 }
56}
57

Callers 5

modelStrings.tsFile · 0.85
magicDocs.tsFile · 0.85
sessionMemory.tsFile · 0.85

Calls 2

processQueueFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected