2020-09-17 06:05:45 +00:00
|
|
|
import 'reflect-metadata';
|
2020-08-21 16:38:21 +00:00
|
|
|
import { EventLayer } from "../lib/communication/eventLayer";
|
2020-08-25 22:11:26 +00:00
|
|
|
import { getLinkedDispatcher } from "../lib/dispatcher/getLinkedDispatcher";
|
|
|
|
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
|
|
|
|
import { exportFunctionToDispatcher } from "../lib/dispatcher/nopeDispatcherDecorators";
|
2020-10-13 16:22:04 +00:00
|
|
|
import { NopeObservable } from '../lib/observables/NopeObservable';
|
2020-09-28 16:38:35 +00:00
|
|
|
import { IRemoteInstance } from '../lib/types/remoteInstance.interface';
|
2020-10-13 16:22:04 +00:00
|
|
|
import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction";
|
|
|
|
|
2020-08-21 16:38:21 +00:00
|
|
|
|
2020-09-13 14:09:01 +00:00
|
|
|
let max = 100000;
|
|
|
|
const communicator = new EventLayer(
|
|
|
|
'generic',
|
|
|
|
'generic'
|
|
|
|
);
|
2020-10-13 16:22:04 +00:00
|
|
|
const local = new nopeDispatcher({ communicator }, () => new NopeObservable());
|
2020-08-25 22:11:26 +00:00
|
|
|
const _functionRemote = exportFunctionToDispatcher(async (a: number, b: number, operation: (a: number, b: number) => number) => {
|
2020-08-21 16:38:21 +00:00
|
|
|
return await operation(a, b);
|
2020-08-25 22:11:26 +00:00
|
|
|
}, {
|
2020-09-13 14:09:01 +00:00
|
|
|
uri: 'functionRemote'
|
|
|
|
});
|
|
|
|
const _benchmark = exportFunctionToDispatcher(generateBenchmarkFunction(max, ''), {
|
|
|
|
uri: 'benchmark'
|
2020-08-21 16:38:21 +00:00
|
|
|
});
|
2020-09-12 00:59:30 +00:00
|
|
|
const remote = getLinkedDispatcher({ communicator });
|
2020-10-13 16:22:04 +00:00
|
|
|
const remoteObservable = new NopeObservable<number>()
|
2020-09-17 06:05:45 +00:00
|
|
|
remote.registerObservable(remoteObservable,{
|
|
|
|
mode: 'publish',
|
|
|
|
topic: 'topic'
|
|
|
|
});
|
2020-08-25 22:11:26 +00:00
|
|
|
|
2020-08-21 16:38:21 +00:00
|
|
|
const main = async () => {
|
2020-09-17 06:05:45 +00:00
|
|
|
|
2020-10-13 16:22:04 +00:00
|
|
|
const localObservable = new NopeObservable<number>();
|
2020-09-17 06:05:45 +00:00
|
|
|
localObservable.subscribe((data) => {
|
|
|
|
console.log(data)
|
|
|
|
});
|
|
|
|
|
|
|
|
remoteObservable.setContent(1337);
|
|
|
|
console.log('No output of the emitter');
|
|
|
|
|
|
|
|
local.registerObservable(localObservable,{
|
|
|
|
mode: 'subscribe',
|
|
|
|
topic:'topic'
|
|
|
|
});
|
|
|
|
|
|
|
|
remoteObservable.setContent(1338)
|
|
|
|
|
|
|
|
|
2020-09-12 00:59:30 +00:00
|
|
|
try {
|
|
|
|
await local.performCall('unkown', []);
|
|
|
|
} catch (e) {
|
2020-09-17 06:05:45 +00:00
|
|
|
console.log('Successfully thrown Error. Function isnt available.');
|
2020-09-12 00:59:30 +00:00
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
|
2020-09-13 14:09:01 +00:00
|
|
|
let res = await local.performCall<number>('functionRemote', [1, 2, async (a, b) => {
|
2020-08-21 16:38:21 +00:00
|
|
|
console.log('local callback')
|
|
|
|
return a + b;
|
|
|
|
}]);
|
|
|
|
|
|
|
|
console.log('1', res)
|
|
|
|
|
2020-09-13 14:09:01 +00:00
|
|
|
res = await local.methodInterface.functionRemote<number>(1, 2, async (a, b) => {
|
2020-08-21 16:38:21 +00:00
|
|
|
console.log('local callback')
|
|
|
|
return a * b;
|
2020-09-13 10:35:04 +00:00
|
|
|
});
|
2020-08-21 16:38:21 +00:00
|
|
|
|
2020-11-04 16:33:36 +00:00
|
|
|
remote.registerInternalInstanceGenerator('class', async (dispather, identifier) => {
|
2020-09-28 16:38:35 +00:00
|
|
|
const ret: IRemoteInstance = {
|
|
|
|
dispose: async () => {
|
|
|
|
console.log('dispise')
|
|
|
|
},
|
2020-11-04 16:33:36 +00:00
|
|
|
description: {
|
|
|
|
|
|
|
|
},
|
2020-09-28 16:38:35 +00:00
|
|
|
init: async (... args) => {
|
|
|
|
console.log('INIT with', args)
|
|
|
|
},
|
|
|
|
type: 'class'
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('CREATED INSTANCE of type "class" with args',dispather.id, identifier);
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}, {
|
|
|
|
mode: 'external'
|
|
|
|
});
|
|
|
|
|
|
|
|
local.registerInstanceGenerator('class', async (dispather, identifier) => {
|
|
|
|
const ret: IRemoteInstance = {
|
|
|
|
dispose: async () => {
|
|
|
|
console.log('dispise')
|
|
|
|
},
|
|
|
|
identifier: 'null',
|
|
|
|
init: async (... args) => {
|
|
|
|
console.log('INIT with', args)
|
|
|
|
},
|
|
|
|
type: 'class'
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('CREATED Wrapper for', identifier);
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}, {
|
|
|
|
mode: 'internal'
|
|
|
|
});
|
|
|
|
|
|
|
|
const instance_01= await local.generateInstance({
|
|
|
|
identifier: 'obj1',
|
|
|
|
params: ['hello','world'],
|
|
|
|
type: 'class'
|
|
|
|
});
|
|
|
|
|
|
|
|
const instance_02 = await local.generateInstance({
|
|
|
|
identifier: 'obj1',
|
|
|
|
params: ['hello','world'],
|
|
|
|
type: 'class'
|
|
|
|
});
|
|
|
|
|
2020-09-13 14:09:01 +00:00
|
|
|
|
2020-08-25 22:11:26 +00:00
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
const benchmark = generateBenchmarkFunction(max, '');
|
|
|
|
|
|
|
|
while (i < max * 10) {
|
2020-09-13 14:09:01 +00:00
|
|
|
await local.performCall<number>('functionRemote', [1, 2, async (a, b) => {
|
2020-08-25 22:11:26 +00:00
|
|
|
return 1
|
|
|
|
}], {
|
2020-09-12 00:59:30 +00:00
|
|
|
deletableCallbacks: [2],
|
2020-08-25 22:11:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
benchmark();
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2020-08-21 16:38:21 +00:00
|
|
|
|
2020-09-13 14:09:01 +00:00
|
|
|
const opts = {
|
|
|
|
deletableCallbacks: []
|
|
|
|
};
|
|
|
|
const args = []
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < max * 10) {
|
|
|
|
await local.performCall<void>('benchmark', args, opts);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2020-09-28 16:38:35 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < max * 10) {
|
|
|
|
await benchmark();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2020-08-21 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 14:09:01 +00:00
|
|
|
main().catch(console.error);
|
|
|
|
|
|
|
|
setTimeout(console.log, 10000, 'done');
|
2020-08-21 16:38:21 +00:00
|
|
|
|