Skip to content

Commit

Permalink
feat(core): MsgCallback is now typed as returning `void | Promise<nev…
Browse files Browse the repository at this point in the history
…er>` to indicate that they cannot contain `await` (#202)

Signed-off-by: Alberto Ricart <[email protected]>
  • Loading branch information
aricart authored Feb 4, 2025
1 parent 6a0a9b7 commit 3d448c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export type Status =
| SlowConsumerStatus
| ForceReconnectStatus;

export type MsgCallback<T> = (err: Error | null, msg: T) => void;
export type MsgCallback<T> = (
err: Error | null,
msg: T,
) => void | Promise<never>;

/**
* Subscription Options
Expand Down
5 changes: 2 additions & 3 deletions core/tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,8 @@ Deno.test("basics - request many waits for timer late response", async () => {

const subj = createInbox();
nc.subscribe(subj, {
callback: async (_err, msg) => {
await delay(1750);
msg.respond();
callback: (_err, msg) => {
delay(1759).then(() => msg.respond());
},
});

Expand Down
7 changes: 4 additions & 3 deletions core/tests/mrequest_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ async function requestTimerLateResponse(noMux = false): Promise<void> {

const subj = createInbox();
nc.subscribe(subj, {
callback: async (_err, msg) => {
await delay(1750);
msg.respond();
callback: (_err, msg) => {
delay(1750).then(() => {
msg.respond();
});
},
});

Expand Down

0 comments on commit 3d448c9

Please sign in to comment.