Repository navigation
Expand file tree
/
Copy pathdelay.js
More file actions
42 lines (37 loc) · 1.31 KB
/
Copy pathdelay.js
File metadata and controls
42 lines (37 loc) · 1.31 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
module.exports = function (delay, fromId) {
var microDelay = 15;
var id = 0;
if (fromId) { loupe.skipDelays = true; }
var nMicroDelays = delay / microDelay;
return function () {
id++;
var microId = 0;
var start, target;
var countdown = Math.floor(nMicroDelays);
//var wasSkipping = loupe.skipDelays;
//var startedAt = new Date().getTime();
while (countdown--) {
weevil.send('delay', id + microId);
loupe.triggerDelay(id + microId);
if (!fromId || (id + microId) > fromId) {
loupe.skipDelays = false;
start = new Date().getTime();
target = start + microDelay;
while (new Date().getTime() < target) {
//no-op
}
}
microId += 0.000001;
}
//var actual = new Date().getTime() - startedAt;
//if (loupe.skipDelays) {
// console.log(['Skipped', id, 'in', actual]);
//} else {
// if (wasSkipping) {
// console.log([id, 'Partial!', delay, 'actual', actual, 'error', actual - delay]);
// } else {
// console.log([id, 'Target', delay, 'actual', actual, 'error', actual - delay]);
// }
//}
};
};