github
135 of 194 branches covered (69.59%)
Branch coverage included in aggregate %.
187 of 208 new or added lines in 5 files covered. (89.9%)
1393 of 1717 relevant lines covered (81.13%)
19.67 hits per line
|
export function createTaskQueue() {
|
5✔ |
|
// deno-lint-ignore no-explicit-any
|
28✔ |
|
const array: any = [];
|
28✔ |
4 |
|
|
|
let isExecuting = false;
|
28✔ |
|
async function exec() { |
28✔ |
|
while (array.length > 0) { |
|
|
const { fn, args, resolve } = array.shift();
|
52✔ |
|
try {
|
52✔ |
|
const result = await fn(...args);
|
52✔ |
|
resolve(result); |
52✔ |
NEW
|
} catch (error) {
|
|
NEW
|
console.error("Error executing function:", error);
|
× |
NEW
|
} |
× |
|
} |
52✔ |
|
isExecuting = false;
|
39✔ |
|
} |
39✔ |
18 |
|
|
|
// deno-lint-ignore no-explicit-any
|
28✔ |
|
function process<T extends any[], R>( |
28✔ |
|
fn: (...args: T) => Promise<R> | R, |
28✔ |
|
...args: T |
28✔ |
23 |
): Promise<R> { |
|
|
return new Promise((resolve) => { |
41✔ |
|
array.push({ fn, args, resolve }); |
270✔ |
|
if (!isExecuting) {
|
|
|
isExecuting = true;
|
65✔ |
|
exec(); |
65✔ |
|
} |
65✔ |
|
}); |
41✔ |
|
} |
41✔ |
32 |
|
|
|
return { process: process }; |
84✔ |
|
} |
28✔ |