MCPcopy Create free account
hub / github.com/msgbyte/tailchat / createAutoSplitRequest

Function createAutoSplitRequest

client/shared/utils/request.ts:61–89  ·  view source on GitHub ↗
(
  fn: (keys: Key[]) => Promise<Item[]>,
  type: 'serial' | 'parallel',
  limit = 100
)

Source from the content-addressed store, hash-verified

59 * 创建一个自动拆分请求参数的函数
60 */
61export function createAutoSplitRequest<Key, Item>(
62 fn: (keys: Key[]) => Promise<Item[]>,
63 type: 'serial' | 'parallel',
64 limit = 100
65): (arr: Key[]) => Promise<Item[]> {
66 return async (arr: Key[]): Promise<Item[]> => {
67 const groups = _chunk(arr, limit);
68
69 if (type === 'serial') {
70 const list: Item[] = [];
71 for (const group of groups) {
72 const res = await fn(group);
73 if (Array.isArray(res)) {
74 list.push(...res);
75 } else {
76 console.warn('[createAutoSplitRequest] fn should be return array');
77 }
78 }
79
80 return list;
81 } else if (type === 'parallel') {
82 const res = await Promise.all(groups.map((group) => fn(group)));
83
84 return _flatten(res);
85 }
86
87 return [];
88 };
89}

Callers 3

converse.tsFile · 0.90
user.tsFile · 0.90
message.tsFile · 0.90

Calls 3

warnMethod · 0.80
fnFunction · 0.50
allMethod · 0.45

Tested by

no test coverage detected