Typescript all the parser things
This commit is contained in:
19
app/imports/api/utility/asyncMap.ts
Normal file
19
app/imports/api/utility/asyncMap.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Async compatible map that processes all items in parallel
|
||||
*/
|
||||
export async function parallelMap(array: any[], fn: (doc: any) => Promise<any>): Promise<any[]> {
|
||||
return await Promise.all(array.map(fn));
|
||||
}
|
||||
|
||||
/**
|
||||
* Async compatible map that processes all items in series
|
||||
*/
|
||||
export async function serialMap(array: any[], fn: (doc: any) => Promise<any>): Promise<any[]> {
|
||||
const results: any[] = [];
|
||||
for (const doc of array) {
|
||||
const result = await fn(doc);
|
||||
results.push(result);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user