72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import { AmqpLayer, } from "../lib/communication/amqpLayer";
|
|
import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction";
|
|
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
|
|
import { promisify } from 'util'
|
|
import { getLogger } from "../lib/logger/getLogger";
|
|
|
|
const client1 = new AmqpLayer('localhost');
|
|
const client2 = new AmqpLayer('localhost');
|
|
const client3 = new AmqpLayer('localhost');
|
|
|
|
|
|
const sleep = promisify(setTimeout)
|
|
|
|
function genFunc(name, delay) {
|
|
const logger = getLogger('debug',name)
|
|
return (idx: number) => {
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
logger.info('started ' + idx.toString());
|
|
setTimeout(() => {
|
|
logger.info('finished ' + idx.toString());
|
|
resolve();
|
|
}, delay);
|
|
} catch(e){
|
|
reject(e)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|
|
|
|
const main = async () => {
|
|
await sleep(1000);
|
|
const dispatcher3 = new nopeDispatcher({ communicator: client3 });
|
|
const dispatcher1 = new nopeDispatcher({ communicator: client1 });
|
|
const dispatcher2 = new nopeDispatcher({ communicator: client2 });
|
|
await sleep(1000);
|
|
const benchmark = generateBenchmarkFunction(10000, 'Executed')
|
|
// Register Functions
|
|
dispatcher1.registerFunction(genFunc('dispatcher-1-slow', 1000), {
|
|
id: 'func'
|
|
});
|
|
dispatcher2.registerFunction(genFunc('dispatcher-2-fast', 2000), {
|
|
id: 'func'
|
|
});
|
|
await sleep(1000);
|
|
|
|
let c = 0
|
|
// Call Tasks Parallel!
|
|
while (c < 10) {
|
|
dispatcher3.performCall('func', [c++]).catch(e => console.error(e));
|
|
}
|
|
|
|
// await client1.on('subscribe','test_01', (...args) => {
|
|
// console.log('c1',...args);
|
|
// })
|
|
|
|
// await client2.on('subscribe','test_02', (...args) => {
|
|
// benchmark()
|
|
// })
|
|
|
|
// let i = 0;
|
|
// let max = 100000;
|
|
// while(i < max){
|
|
// await client1.emit('publish','test_02', i)
|
|
// i++;
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
main(); |