I'm new to writing browser extensions and am working on some changes to a Firefox extension. While reading the documentation for browser.runtime.onMessage.addListener() I came across this note:
Note: If you pass an async function to addListener(), the listener will return a Promise for every message it receives, preventing other listeners from responding:
// don't do this
browser.runtime.onMessage.addListener(
async (data, sender) => {
if (data.type === 'handle_me') { return 'done'; }
}
);
Despite this, however, async addListener() functions seem to be used somewhat commonly from what I can tell (at least, I've seen them in code for widely-used and well-known extensions as well as in examples provided by people on various forums threads, etc.).
Can somebody provide some details on why this should be avoided and/or whether it is only a problem in certain scenarios? It says returning a Promise for every message received will prevent other listeners from responding... does that mean this is only an issue if you have multiple listeners attached? Or is it something that should always be avoided no matter what?
Any insight is appreciated!