mdn / sprints

Archived: MDN Web Docs issues are tracked in the content repository.
https://github.com/mdn/content
Creative Commons Zero v1.0 Universal
150 stars 142 forks source link

Confusing warning about async runtime.onMessage listeners #3927

Closed nickgaya closed 3 years ago

nickgaya commented 3 years ago

Request type

Details

The documentation for runtime.onMessage.addListener() has a warning box that states:

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.

Cimeone commented 3 years ago

I'd be happy to address this, could it please be assigned to me.

chrisdavidmills commented 3 years ago

@Cimeone assigned, thanks.

chrisdavidmills commented 3 years ago

Issue moved to mdn/content #1452 via ZenHub