mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
tweak(resources/promise-events): Tweak promise event resp and req types
This commit is contained in:
1 parent
f54dc974a2
commit
dcb7556edc
3 files changed
+15
-7
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { getSource } from '../miscUtils';
|
||||
import { mainLogger } from '../../sv_logger';
|
||||
import { CBSignature, PromiseEventReturnFunc, PromiseRequest } from './promise.types';
|
||||
import { CBSignature, PromiseEventResp, PromiseRequest } from './promise.types';
|
||||
import { ServerPromiseResp } from '../../../../typings/common';
|
||||
|
||||
const netEventLogger = mainLogger.child({ module: 'events' });
|
||||
|
||||
export function onNetPromise<T>(eventName: string, cb: CBSignature<T>): void {
|
||||
export function onNetPromise<T = any, P = any>(eventName: string, cb: CBSignature<T, P>): void {
|
||||
onNet(eventName, async (respEventName: string, data: T) => {
|
||||
const src = getSource();
|
||||
|
||||
@@ -13,7 +14,7 @@ export function onNetPromise<T>(eventName: string, cb: CBSignature<T>): void {
|
||||
data,
|
||||
};
|
||||
|
||||
const promiseResp: PromiseEventReturnFunc = (data: unknown) => {
|
||||
const promiseResp: PromiseEventResp<P> = (data: ServerPromiseResp<P>) => {
|
||||
emitNet(respEventName, src, data);
|
||||
netEventLogger.debug(`Response Promise Event ${respEventName}, Data >>`);
|
||||
netEventLogger.debug(data);
|
||||
@@ -25,7 +26,7 @@ export function onNetPromise<T>(eventName: string, cb: CBSignature<T>): void {
|
||||
`An error occured for a onNetPromise (${eventName}), Error: ${e.message}`,
|
||||
);
|
||||
|
||||
promiseResp({ err: true, errMsg: 'Server error occurred' });
|
||||
promiseResp({ status: 'error', errorMsg: 'Server error occurred' });
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
export interface PromiseRequest<T> {
|
||||
import { ServerPromiseResp } from '../../../../typings/common';
|
||||
|
||||
export interface PromiseRequest<T = any> {
|
||||
data: T;
|
||||
source: number;
|
||||
}
|
||||
|
||||
export type PromiseEventReturnFunc = (returnData: unknown) => void;
|
||||
export type PromiseEventResp<T> = (returnData: ServerPromiseResp<T>) => void;
|
||||
|
||||
export type CBSignature<T> = (reqObj: PromiseRequest<T>, resp: PromiseEventReturnFunc) => void;
|
||||
export type CBSignature<T, P> = (reqObj: PromiseRequest<T>, resp: PromiseEventResp<P>) => void;
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface ServerPromiseResp<T = undefined> {
|
||||
errorMsg?: string;
|
||||
status: 'ok' | 'error';
|
||||
data?: T;
|
||||
}
|
||||
Reference in new issue
Block a user