Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed async function calls in server/client callbacks #340

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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