nope/test/testDispatcher.ts
2020-08-26 00:11:26 +02:00

52 lines
1.4 KiB
TypeScript

import { EventLayer } from "../lib/communication/eventLayer";
import { getLinkedDispatcher } from "../lib/dispatcher/getLinkedDispatcher";
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
import { exportFunctionToDispatcher } from "../lib/dispatcher/nopeDispatcherDecorators";
import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction";
const communicationLayer = new EventLayer();
const local = new nopeDispatcher(communicationLayer);
const _functionRemote = exportFunctionToDispatcher(async (a: number, b: number, operation: (a: number, b: number) => number) => {
return await operation(a, b);
}, {
uri: '_functionRemote'
});
const remote = getLinkedDispatcher(communicationLayer);
const main = async () => {
let res = await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
console.log('local callback')
return a + b;
}]);
console.log('1', res)
res = await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
console.log('local callback')
return a * b;
}]);
let max = 100000;
let i = 0;
const benchmark = generateBenchmarkFunction(max, '');
while (i < max * 10) {
await local.performCall<number>('_functionRemote', [1, 2, async (a, b) => {
return 1
}], {
deletableCallbacks: [2]
});
benchmark();
i++;
}
}
main();