Skip to content

Commit

Permalink
fix(package/callback): await callback response (overextended#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
GenerousImpersio authored May 25, 2023
1 parent a8ab102 commit 467e7f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package/client/resource/callback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function triggerServerCallback<T = unknown>(
}

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;

try {
response = cb(...args);
response = await cb(...args);
} catch (e: any) {
console.error(`an error occurred while handling callback event ${eventName}`);
console.log(`^3${e.stack}^0`);
Expand Down
4 changes: 2 additions & 2 deletions package/server/resource/callback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export function triggerClientCallback<T = unknown>(
}

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;
let response: any;

try {
response = cb(src, ...args);
response = await cb(src, ...args);
} catch (e: any) {
console.error(`an error occurred while handling callback event ${eventName}`);
console.log(`^3${e.stack}^0`);
Expand Down

0 comments on commit 467e7f5

Please sign in to comment.