mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
tweak(server/onNetPromise): Tweak to be less opinionated and simpler
This commit is contained in:
1 parent
fed042aea7
commit
b257f5bc73
4 files changed
+13
-133
No files matched your search
@@ -1,22 +1,23 @@
|
||||
import { ErrorStringKeys } from '../../../../typings/phone';
|
||||
import { getSource } from '../miscUtils';
|
||||
import { PromiseResponse } from './PromiseResponse';
|
||||
import { mainLogger } from '../../sv_logger';
|
||||
import { CBSignature, PromiseRequest, PromiseRequestData } from './promise.types';
|
||||
import { CBSignature, PromiseEventReturnFunc, PromiseRequest } from './promise.types';
|
||||
|
||||
const netEventLogger = mainLogger.child({ module: 'events' });
|
||||
|
||||
export function onNetPromise<T>(eventName: string, cb: CBSignature<T>) {
|
||||
onNet(eventName, async (respEventName: string, data: PromiseRequestData<T>) => {
|
||||
export function onNetPromise<T>(eventName: string, cb: CBSignature<T>): void {
|
||||
onNet(eventName, async (respEventName: string, data: T) => {
|
||||
const src = getSource();
|
||||
|
||||
const promiseRequest: PromiseRequest<T> = {
|
||||
source: src,
|
||||
body: data,
|
||||
data,
|
||||
};
|
||||
|
||||
// Lets hope GC can clean you up
|
||||
const promiseResp = new PromiseResponse(respEventName, src);
|
||||
const promiseResp: PromiseEventReturnFunc = (data: unknown) => {
|
||||
emitNet(respEventName, src, data);
|
||||
netEventLogger.debug(`Response Promise Event ${respEventName}, Data >>`);
|
||||
netEventLogger.debug(data);
|
||||
};
|
||||
|
||||
// In case the cb is a promise, we use Promise.resolve
|
||||
Promise.resolve(cb(promiseRequest, promiseResp)).catch((e) => {
|
||||
@@ -24,10 +25,7 @@ export function onNetPromise<T>(eventName: string, cb: CBSignature<T>) {
|
||||
`An error occured for a onNetPromise (${eventName}), Error: ${e.message}`,
|
||||
);
|
||||
|
||||
promiseResp.sendError({
|
||||
errorCode: ErrorStringKeys.SERVER_ERROR,
|
||||
message: 'An error occured on the server',
|
||||
});
|
||||
promiseResp({ err: true, errMsg: 'Server error occurred' });
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user