import "reflect-metadata"; import { EventLayer } from "../lib/communication/eventLayer"; import { exportFunctionToDispatcher } from "../lib/decorators/dispatcherDecorators"; import { getLinkedDispatcher } from "../lib/dispatcher/getLinkedDispatcher"; import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher"; import { NopeObservable } from "../lib/observables/NopeObservable"; import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction"; const max = 100000; const communicator = new EventLayer(); const local = new nopeDispatcher({ communicator }, () => new NopeObservable()); const _functionRemote = exportFunctionToDispatcher( async (a: number, b: number, operation: (a: number, b: number) => number) => { return await operation(a, b); }, { id: "functionRemote" } ); const _benchmark = exportFunctionToDispatcher( generateBenchmarkFunction(max, "remote-dispatcher"), { id: "benchmark" } ); const remote = getLinkedDispatcher({ communicator }); const remoteObservable = new NopeObservable(); remote.registerObservable(remoteObservable, { mode: "publish", topic: "topic", schema: {} }); const main = async () => { const localObservable = new NopeObservable(); localObservable.subscribe((data) => { console.log(data); }); remoteObservable.setContent(1337); console.log("No output of the emitter"); local.registerObservable(localObservable, { mode: "subscribe", topic: "topic", schema: {} }); remoteObservable.setContent(1338); try { await local.performCall("unkown", []); } catch (e) { console.log("Successfully thrown Error. Function isnt available."); console.error(e); } let res = await local.performCall("functionRemote", [ 1, 2, async (a, b) => { console.log("local callback"); return a + b; } ]); console.log("1", res); res = await local.methodInterface.functionRemote( 1, 2, async (a, b) => { console.log("local callback"); return a * b; } ); let i = 0; const benchmark = generateBenchmarkFunction(max, ""); while (i < max * 10) { // await local.performCall( // "functionRemote", // [ // 1, // 2, // async (a, b) => { // return 1; // } // ], // { // deletableCallbacks: [2] // } // ); benchmark(); i++; } const opts = { deletableCallbacks: [] }; const args = []; i = 0; while (i < max * 10) { await local.performCall("benchmark", args, opts); i++; } i = 0; while (i < max * 10) { await _benchmark(); i++; } await local.dispose(); await remote.dispose(); }; main().catch(console.error);