-
Notifications
You must be signed in to change notification settings - Fork 3
/
global.js
48 lines (44 loc) · 2.02 KB
/
global.js
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
45
46
47
48
const globalFifoByTypeRule = require('./globalfifobytype');
const globalFifoByTimeoutRule = require('./globalfifobytimeout');
const globalNextTickRule = require('./nexttick');
function apply(entries, asyncObjects, relations) {
let newRelationsFound = false; // eslint-disable-line no-unused-vars
let asyncObj = asyncObjects.getAll();
for (let i = 0; i < asyncObj.length; i++) {
for (let j = i + 1; j < asyncObj.length; j++) {
let aoi = asyncObj[i], aoj = asyncObj[j];
//same type
if (aoi.entry.type === aoj.entry.type &&
!relations.happensBefore(aoi.id, aoj.id) &&
!relations.happensBefore(aoj.id, aoi.id)) {
switch (aoi.entry.type) {
case 'Immediate':
case 'TickObject':
case 'PROMISE':
if (globalFifoByTypeRule.apply(entries, asyncObjects, relations, aoi, aoj))
newRelationsFound = true;
break;
case 'Timeout':
if (globalFifoByTimeoutRule.apply(entries, asyncObjects, relations, aoi, aoj))
newRelationsFound = true;
break;
}
}
//tick case
if (isOneOfTick(aoi, aoj) &&
!relations.happensBefore(aoi.id, aoj.id) &&
!relations.happensBefore(aoj.id, aoi.id)) {
if (globalNextTickRule.apply(entries, asyncObjects, relations, aoi, aoj))
newRelationsFound = true;
}
}
}
// REMOVE IT FOR SCALABILITY
// if (newRelationsFound) //if a new relation is found, the process needs to be restarted
// apply(entries, asyncObjects, relations);
}
function isOneOfTick(aoi, aoj) { //different types, but one is tick
let itype = aoi.entry.type, jtype = aoj.entry.type;
return itype !== jtype && (itype === 'TickObject' || jtype === 'TickObject');
}
module.exports = { apply }