Skip to content

Commit 802dbb3

Browse files
committed
refactor: update publishMessage calls for consistency and error handling
- Changed `void publishMessage` to `await publishMessage` in comment actions to ensure proper asynchronous handling. - Updated the `publishMessage` function in pusher.server.ts to return a value, improving error handling and consistency in message publishing. - Adjusted notification function in inngest.ts to return the result of `publishMessage`, enhancing clarity in notification flow.
1 parent c306fea commit 802dbb3

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/backend/services/comment.action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const createMyComment = async (
7575
console.error("[inngest] Failed to send notification event:", err);
7676
});
7777

78-
void publishMessage(
78+
await publishMessage(
7979
`resource.${resource_type}.${resource_id}`,
8080
REALTIME_PUSHER_EVENTS.COMMENT_CREATED,
8181
{ scope: "comments" },
@@ -110,7 +110,7 @@ export const updateMyComment = async (
110110
data: { body: input.body, updated_at: new Date() },
111111
});
112112

113-
void publishMessage(
113+
await publishMessage(
114114
`resource.${existing.resource_type}.${existing.resource_id}`,
115115
REALTIME_PUSHER_EVENTS.COMMENT_UPDATED,
116116
{ scope: "comments" },
@@ -168,7 +168,7 @@ export const deleteMyComment = async (
168168
where: inArray("id", ids),
169169
});
170170

171-
void publishMessage(
171+
await publishMessage(
172172
`resource.${root.resource_type}.${root.resource_id}`,
173173
REALTIME_PUSHER_EVENTS.COMMENT_DELETED,
174174
{ scope: "comments" },

src/lib/inngest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const persistNotificationFn = inngest.createFunction(
196196
});
197197

198198
await step.run("publish-notification-realtime", async () => {
199-
await publishMessage(
199+
return await publishMessage(
200200
`private-user.${data.recipient_id}`,
201201
REALTIME_PUSHER_EVENTS.NOTIFICATION_NEW,
202202
{ scope: "notifications" },

src/lib/pusher/pusher.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ export async function publishMessage(
3636
channel: string,
3737
event: RealtimePusherEvent,
3838
data: Record<string, unknown> = {},
39-
): Promise<void> {
39+
) {
4040
if (!pusherServer) return;
4141
try {
42-
await pusherServer.trigger(channel, event, data);
42+
return await pusherServer.trigger(channel, event, data);
4343
} catch (err) {
4444
console.error("[pusher] Failed to publish message:", JSON.stringify(err));
45+
return null;
4546
}
4647
}

0 commit comments

Comments
 (0)