fix(core): update

This commit is contained in:
Philipp Kunz 2020-12-16 01:38:57 +00:00
parent 15df24bf68
commit 57c748657a
3 changed files with 18 additions and 9 deletions

View File

@ -15,7 +15,7 @@ let testSocketFunction1: smartsocket.SocketFunction<any>;
let myseServer: smartexpress.Server; let myseServer: smartexpress.Server;
const testConfig = { const testConfig = {
port: 3000, port: 3005,
}; };
// class smartsocket // class smartsocket
@ -87,10 +87,19 @@ tap.test('2 clients should connect in parallel', async () => {
}); });
tap.test('should be able to make a functionCall from client to server', async () => { tap.test('should be able to make a functionCall from client to server', async () => {
const response = await testSmartsocketClient.serverCall('testFunction1', { const totalCycles = 20000
value1: 'hello', let counter = 0;
}); let startTime = Date.now();
console.log(response); while (counter < totalCycles) {
const response = await testSmartsocketClient.serverCall('testFunction1', {
value1: 'hello',
});
if (counter % 100 === 0) {
console.log(`processed 100 more messages in ${Date.now() - startTime}ms. ${totalCycles - counter} messages to go.`);
startTime = Date.now();
};
counter++;
}
}); });
tap.test('should be able to make a functionCall from server to client', async () => {}); tap.test('should be able to make a functionCall from server to client', async () => {});

View File

@ -143,7 +143,7 @@ export class SocketConnection {
} }
}); });
this.socket.on('functionResponse', (dataArg: ISocketRequestDataObject<any>) => { this.socket.on('functionResponse', (dataArg: ISocketRequestDataObject<any>) => {
logger.log('info', `received response for request with id ${dataArg.shortId}`); // logger.log('info', `received response for request with id ${dataArg.shortId}`);
const targetSocketRequest = SocketRequest.getSocketRequestById( const targetSocketRequest = SocketRequest.getSocketRequestById(
this.smartsocketRef, this.smartsocketRef,
dataArg.shortId dataArg.shortId

View File

@ -90,7 +90,7 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
* handles the response that is received by the requesting side * handles the response that is received by the requesting side
*/ */
public async handleResponse(responseDataArg: ISocketRequestDataObject<T>) { public async handleResponse(responseDataArg: ISocketRequestDataObject<T>) {
logger.log('info', 'handling response!'); // logger.log('info', 'handling response!');
this.done.resolve(responseDataArg.funcCallData); this.done.resolve(responseDataArg.funcCallData);
this.smartsocketRef.socketRequests.remove(this); this.smartsocketRef.socketRequests.remove(this);
} }
@ -110,11 +110,11 @@ export class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedReques
logger.log('error', `There is no SocketFunction defined for ${this.funcCallData.funcName}`); logger.log('error', `There is no SocketFunction defined for ${this.funcCallData.funcName}`);
return; return;
} }
logger.log('info', `invoking ${targetSocketFunction.name}`); // logger.log('info', `invoking ${targetSocketFunction.name}`);
targetSocketFunction targetSocketFunction
.invoke(this.funcCallData, this.originSocketConnection) .invoke(this.funcCallData, this.originSocketConnection)
.then((resultData) => { .then((resultData) => {
logger.log('info', 'got resultData. Sending it to requesting party.'); // logger.log('info', 'got resultData. Sending it to requesting party.');
const responseData: ISocketRequestDataObject<T> = { const responseData: ISocketRequestDataObject<T> = {
funcCallData: resultData, funcCallData: resultData,
shortId: this.shortid, shortId: this.shortid,