mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
fix(package/callback): await callback response (#340)
This commit is contained in:
@@ -42,11 +42,11 @@ export function triggerServerCallback<T = unknown>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function onServerCallback(eventName: string, cb: (...args) => any) {
|
export function onServerCallback(eventName: string, cb: (...args) => any) {
|
||||||
onNet(`__ox_cb_${eventName}`, (resource: string, key: string, ...args) => {
|
onNet(`__ox_cb_${eventName}`, async (resource: string, key: string, ...args) => {
|
||||||
let response: any;
|
let response: any;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = cb(...args);
|
response = await cb(...args);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(`an error occurred while handling callback event ${eventName}`);
|
console.error(`an error occurred while handling callback event ${eventName}`);
|
||||||
console.log(`^3${e.stack}^0`);
|
console.log(`^3${e.stack}^0`);
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ export function triggerClientCallback<T = unknown>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function onClientCallback(eventName: string, cb: (playerId: number, ...args) => any) {
|
export function onClientCallback(eventName: string, cb: (playerId: number, ...args) => any) {
|
||||||
onNet(`__ox_cb_${eventName}`, (resource: string, key: string, ...args) => {
|
onNet(`__ox_cb_${eventName}`, async (resource: string, key: string, ...args) => {
|
||||||
const src = source;
|
const src = source;
|
||||||
let response: any;
|
let response: any;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = cb(src, ...args);
|
response = await cb(src, ...args);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(`an error occurred while handling callback event ${eventName}`);
|
console.error(`an error occurred while handling callback event ${eventName}`);
|
||||||
console.log(`^3${e.stack}^0`);
|
console.log(`^3${e.stack}^0`);
|
||||||
|
|||||||
Reference in New Issue
Block a user