Important: Do not call addListener() using an async function. This will cause the listener to consume every message it receives, effectively blocking all other listeners from receiving and processing messages.
I found this confusing. The underlying issue being described is that an async function always returns a Promise, so passing an async function to addListener() only makes sense if you want a single listener to respond to all messages.
I'm not sure how best to improve the wording. Maybe something like this:
Important: If you call addListener() using an async function, the listener will return a Promise for every message it receives, preventing other listeners from responding. If you only want the listener to respond to messages of a certain type, you must check the message type synchronously before returning a Promise.
Request type
Details
The documentation for
runtime.onMessage.addListener()
has a warning box that states:I found this confusing. The underlying issue being described is that an async function always returns a Promise, so passing an async function to
addListener()
only makes sense if you want a single listener to respond to all messages.I'm not sure how best to improve the wording. Maybe something like this: