Skip to content

Commit 294c6a5

Browse files
committed
Inline helper
1 parent 83919f8 commit 294c6a5

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

source/receiver.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,10 @@ export function isMessengerMessage(message: unknown): message is Message {
2323
);
2424
}
2525

26-
type SendResponse = (response: unknown) => void;
27-
28-
/** Thin Promise-to-sendResponse converter. Don't add logic here */
29-
async function adaptResponse(
30-
sendResponse: SendResponse,
31-
response: Promise<unknown>,
32-
): Promise<void> {
33-
try {
34-
sendResponse(await response);
35-
} catch (error) {
36-
sendResponse({ __webextMessenger: true, error: serializeError(error) });
37-
}
38-
}
39-
4026
function onMessageListener(
4127
message: unknown,
4228
sender: Sender,
43-
sendResponse: SendResponse,
29+
sendResponse: (response: unknown) => void,
4430
): true | undefined {
4531
if (!isMessengerMessage(message)) {
4632
// TODO: Add test for this eventuality: ignore unrelated messages
@@ -58,7 +44,14 @@ function onMessageListener(
5844
return;
5945
}
6046

61-
void adaptResponse(sendResponse, handleMessage(message, sender, action));
47+
(async () => {
48+
try {
49+
sendResponse(await handleMessage(message, sender, action));
50+
} catch (error) {
51+
sendResponse({ __webextMessenger: true, error: serializeError(error) });
52+
}
53+
})();
54+
6255
return true;
6356
}
6457

0 commit comments

Comments
 (0)