-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
44 lines (38 loc) · 1.91 KB
/
test.js
File metadata and controls
44 lines (38 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import asyncUtils from './index.js';
const { groupedConcurrency, DAG, WorkerPool } = asyncUtils;
const dag = new DAG();
const wp = new WorkerPool(5, () => dag.getPending().map(x => x.value), (x) => {
return dag.finish(x);
});
const ins = [
{ id: 1, process: 1, processId: 1, w: async () => console.log(1, Number(process.argv[2]) ? dag : '') },
{ id: 2, depProcess: 1, depId: 1, w: async () => console.log(2, Number(process.argv[2]) ? dag : '') },
{ id: 3, process: 1, processId: 1, w: async () => console.log(3, Number(process.argv[2]) ? dag : '') },
{ id: 4, process: 2, processId: 1, w: async () => console.log(4, Number(process.argv[2]) ? dag : '') },
{ id: 5, process: 2, processId: 1, w: async () => console.log(5, Number(process.argv[2]) ? dag : '') },
// this will be stil serialized, but we have an additional dependency outside
// of the serialized group
{ id: 6, process: 1, processId: 1, dag: [4], w: async () => console.log(6, Number(process.argv[2]) ? dag : '') },
{ id: 7, depProcess: 1, depId: 1, w: async () => console.log(7, Number(process.argv[2]) ? dag : '') },
{ id: 8, process: 2, processId: 1, w: async () => console.log(8, Number(process.argv[2]) ? dag : '') },
{ id: 9, process: 2, processId: 1, w: async () => console.log(9, Number(process.argv[2]) ? dag : '') }
];
for (const x of ins) {
// we have quite some strict serial processes, so we always make sure
// to have a group created even with dag entry existing, so we can
// guarantee to serialize, only dag entries can skip the serialization
// or make it even stricter
const groupKey = x.depId
? `${x.depProcess},${x.depId}`
: `${x.process},${x.processId}`;
console.log('add with gKey', groupKey, x.id);
if (Array.isArray(x.dag)) {
dag.add(x.id, x, x.dag, groupKey);
} else {
dag.add(x.id, x, null, groupKey);
}
}
await wp.fill();
if (Number(process.argv[3])) {
setInterval(() => console.log(dag), 100);
}