MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / startAsync

Function startAsync

src/pkg/utils/async_queue.ts:25–48  ·  view source on GitHub ↗
(stack: TStack<T>)

Source from the content-addressed store, hash-verified

23 * 会依次从 head 开始执行,直到队列为空
24 */
25const startAsync = async <T>(stack: TStack<T>) => {
26 let node;
27 while ((node = stack.head)) {
28 const { task, resolve, reject } = node;
29
30 // 目前节点的 task, resolve, reject 已被取出,清理回调引用
31 node.task = node.resolve = node.reject = null;
32 try {
33 // 执行异步任务
34 const ret = await task!();
35 resolve!(ret);
36 } catch (e: any) {
37 reject!(e);
38 }
39
40 // 移动到下一个节点
41 stack.head = node.next; // 更新head至下一个节点
42 // 目前节点的 next 已被取出,清理引用
43 node.next = null;
44 }
45
46 // 当队列为空时,重置 tail
47 stack.tail = null;
48};
49
50/**
51 * 向指定 key 的队列中添加异步任务

Callers 1

stackAsyncTaskFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected