-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
71 lines (65 loc) · 1.8 KB
/
app.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Discover, SyncObject } from "./module";
const opts = {
ignoreProcess: false,
ignoreInstance: false,
};
const arr: number[] = [];
const events = {
log: () => console.log(performance.now()),
alog: (arg: string) => console.log(performance.now() + arg),
dlog: (arg: string) =>
console.log(
`===================================
Date is: ${+new Date() % 1000000},
event was at: ${arg}
diff is: ${(+new Date() % 1000000) - Number(arg)}`
),
perfcheck: (time: string) => {
const lag = performance.now() - parseFloat(time);
arr.push(lag);
console.log(
`now: ${lag}, avg: ${arr.reduce((x, y) => x + y) / arr.length}`
);
},
};
const sync1 = new SyncObject(
events,
new Discover(opts, () => {
console.log("done1");
console.log(performance.now());
})
);
// const sync2 = new SyncObject(events, new discover(opts,()=>{
// console.log("done2");
// console.log(performance.now())
// }));
//@ts-ignore
//sync1.debugid = "sync1"
//@ts-ignore
// sync2.debugid = "sync2"
//@ts-ignore
// global.debug = {sync1, sync2};
sync1.onPromotion = () => fn3(sync1);
//sync2.onPromotion = () => fn(sync2)
function fn(arg: SyncObject) {
console.log("fn");
return setInterval(() => {
console.log("----------");
console.log(performance.now());
const arg1 = 500;
const arg2 = 800;
arg.scheduleEvent("perfcheck", arg1, (performance.now() + arg1).toString());
arg.scheduleEvent("perfcheck", arg2, (performance.now() + arg2).toString());
}, 2000);
}
function fn2(arg: SyncObject) {
console.log("fn2");
const arg1 = 3000;
arg.scheduleEvent("dlog", arg1, (performance.now() + arg1).toString());
}
function fn3(arg: SyncObject) {
console.log("fn3");
return setInterval(() => {
arg.scheduleEvent("dlog", 500, (+new Date() % 1000000).toString());
}, 1000);
}