2020-09-12 00:59:30 +00:00
|
|
|
import { IoSocketClient } from "../lib/communication/IoSocketClient";
|
2020-09-11 12:07:40 +00:00
|
|
|
import { IoSocketServer } from "../lib/communication/IoSocketServer";
|
2020-09-10 16:21:01 +00:00
|
|
|
import { getLinkedDispatcher } from "../lib/dispatcher/getLinkedDispatcher";
|
2020-09-12 00:59:30 +00:00
|
|
|
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
|
2020-09-10 16:21:01 +00:00
|
|
|
import { exportFunctionToDispatcher } from "../lib/dispatcher/nopeDispatcherDecorators";
|
2020-09-12 00:59:30 +00:00
|
|
|
import { serviceRegistry } from "../lib/dispatcher/serviceRegistry";
|
2020-09-10 16:21:01 +00:00
|
|
|
import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction";
|
|
|
|
|
|
|
|
|
|
|
|
async function exportedFunc(a: number, b: number, operator: (a: number, b: number) => Promise<number>) {
|
|
|
|
return await operator(a, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const test = exportFunctionToDispatcher(exportedFunc, {
|
|
|
|
uri: 'test'
|
|
|
|
})
|
|
|
|
export const benchmark = exportFunctionToDispatcher(generateBenchmarkFunction(1000, 'Executed'), {
|
|
|
|
uri: 'benchmark'
|
|
|
|
})
|
|
|
|
|
2020-09-11 12:07:40 +00:00
|
|
|
const serverIOSocket = new IoSocketServer(9002);
|
2020-09-12 00:59:30 +00:00
|
|
|
const dispatcher = getLinkedDispatcher({
|
|
|
|
communicator: serverIOSocket
|
|
|
|
});
|
|
|
|
|
|
|
|
const IOSocketClient = new IoSocketClient('ws://localhost:9002');
|
|
|
|
const local = new nopeDispatcher({
|
|
|
|
communicator: IOSocketClient
|
|
|
|
});
|
|
|
|
|
|
|
|
const serviceReg = new serviceRegistry({
|
|
|
|
communicator: IOSocketClient
|
|
|
|
})
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
let i = 0;
|
|
|
|
while (i <= 10000) {
|
|
|
|
await local.performCall('benchmark', []);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await local.performCall('unkown', []);
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Succes');
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch(console.error)
|