MCPcopy Index your code
hub / github.com/apache/echarts / runTasks

Function runTasks

test/runTest/task.js:20–70  ·  view source on GitHub ↗
(
    taskParamsLists,
    createTask,
    concurrency
)

Source from the content-addressed store, hash-verified

18*/
19
20function runTasks(
21 taskParamsLists,
22 createTask,
23 concurrency
24) {
25 concurrency = Math.min(taskParamsLists.length, concurrency);
26 return new Promise((resolve, reject) => {
27 let runningTaskCount = 0;
28 let cursor = 0;
29 let rets = [];
30
31 function finishTask(res, idx) {
32 rets[idx] = res;
33 processNext();
34 }
35
36 function failTask(e) {
37 console.error(e);
38 processNext();
39 }
40
41 function processNext() {
42 runningTaskCount--;
43 addTask();
44
45 if (runningTaskCount === 0) {
46 resolve(rets);
47 }
48 }
49
50 function addTask() {
51 const param = taskParamsLists[cursor];
52 if (param) {
53 const currentTaskIdx = cursor;
54 runningTaskCount++;
55 createTask(param)
56 .then((res) => finishTask(res, currentTaskIdx))
57 .catch(failTask);
58 cursor++;
59 }
60 }
61
62 for (let i = 0; i < concurrency; i++) {
63 addTask();
64 }
65
66 if (!runningTaskCount) {
67 resolve(rets);
68 }
69 });
70}
71
72module.exports.runTasks = runTasks;

Callers

nothing calls this directly

Calls 1

addTaskFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…