2020-09-30 06:25:03 +00:00
|
|
|
import 'reflect-metadata';
|
2020-11-09 14:28:09 +00:00
|
|
|
import { promisify } from 'util';
|
|
|
|
import { AmqpLayer } from "../lib/communication/amqpLayer";
|
2020-09-30 06:25:03 +00:00
|
|
|
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
|
2020-11-09 14:28:09 +00:00
|
|
|
import { getNopeLogger } from "../lib/logger/getLogger";
|
|
|
|
import { NopeObservable } from "../lib/observables/nopeObservable";
|
|
|
|
|
2020-09-30 06:25:03 +00:00
|
|
|
|
|
|
|
const client = new AmqpLayer('localhost');
|
|
|
|
|
|
|
|
const sleep = promisify(setTimeout)
|
2020-11-09 14:28:09 +00:00
|
|
|
const logger = getNopeLogger('dispatcher','info')
|
2020-09-30 06:25:03 +00:00
|
|
|
|
|
|
|
const main = async () => {
|
|
|
|
|
|
|
|
let max = 10000;
|
|
|
|
await sleep(1000);
|
|
|
|
|
2020-11-09 14:28:09 +00:00
|
|
|
const dispatcher = new nopeDispatcher({ communicator: client, logger }, () => new NopeObservable());
|
2020-09-30 06:25:03 +00:00
|
|
|
|
|
|
|
await sleep(500);
|
|
|
|
let c = 0
|
|
|
|
// Call Tasks Parallel!
|
|
|
|
while (c < 10) {
|
|
|
|
dispatcher.performCall('func', [c++]).catch(e => console.error(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Benchmark:
|
|
|
|
c = 0
|
|
|
|
|
|
|
|
// Call Tasks Parallel!
|
|
|
|
while (c < max) {
|
|
|
|
await dispatcher.performCall('benchmark', [], {
|
|
|
|
paramsHasNoCallback: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
await sleep(500);
|
2020-11-09 14:28:09 +00:00
|
|
|
const obs01 = new NopeObservable<number>();
|
2020-09-30 06:25:03 +00:00
|
|
|
dispatcher.registerObservable(obs01, {
|
|
|
|
mode: 'publish',
|
|
|
|
topic: 'test.var'
|
|
|
|
});
|
|
|
|
obs01.setContent(1200);
|
|
|
|
|
|
|
|
await sleep(500);
|
|
|
|
c = 0;
|
|
|
|
while (c < max) {
|
|
|
|
obs01.setContent(c++);
|
|
|
|
}
|
|
|
|
|
|
|
|
c = 0;
|
|
|
|
while(c < max){
|
|
|
|
await client.emit('publish','benchmark', c++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|