-
Notifications
You must be signed in to change notification settings - Fork 22.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix explanation in runtime.onMessage doc #3903
Conversation
Preview URLsFlawsURL:
External URLsURL: No new external URLs (this comment was updated 2021-05-19 07:08:35.068293) |
511975c
to
1ce9000
Compare
Preview URLsFlawsURL: No flaws! 🎉 External URLsURL: |
I think I'll leave this one to @muffinresearch , as it's more his area of specialty. You OK to review this one Stuart? |
These changes look ok to me but I'll defer this review to @rpl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sideshowbarker my apologies for not reaching this sooner.
The new wording seems to be at least slightly better, but I have the feeling that it is still a bit open to be misread.
Let's see if we can improve it a bit more.
@sideshowbarker wdyt about the tweaks proposed below?
(by knowing in detail how that works on the implementation side does likely make me unintentionally biased on evaluating how clear it really is from an external reader perspective, and so your perspective on the tweaks I'm proposing is important as much as mine, if not even more).
@@ -111,7 +111,7 @@ <h3 id="Parameters">Parameters</h3> | |||
<p>The <code><var>listener</var></code> function can return either a Boolean or a {{jsxref("Promise")}}.</p> | |||
|
|||
<div class="notecard note"> | |||
<p><strong>Important:</strong> Do not call <code>addListener()</code> using an <code>async</code> function:</p> | |||
<p><strong>Important:</strong> If you call <code>addListener()</code> using an <code>async</code> function, the listener will return a Promise for every message it receives, preventing other listeners from responding:</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, I'm wondering if saying here If you pass to addListener an async function
instead of If you call addListener using an async function
would make it more clear that async function
is referring to the parameter we pass to addListener
not the function inside which we may be calling addListener
.
@muffinresearch what do you think? I would like to hear your pov from an English form perspective (because I may be biased by how my brain automatically translate that phrase in my own language).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest changing that slightly from If you pass to addListener an async function
to If you pass an async function to addListener
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, that does sound better 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpl, @muffinresearch, thanks — change that line so that it now reads:
If you pass an async function to
addListener()
, the listener will return a Promise for every message it receives, preventing other listeners from responding
<p>This will cause the listener to consume every message it receives, effectively blocking all other listeners from receiving and processing messages.</p> | ||
|
||
<p>If you want to take an asynchronous approach, use a Promise instead, like this:</p> | ||
<p>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:</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, you must define the listener as a non-<code>async</code> function, return a Promise only for the messages the listener is meant to respond to, and undefined or false otherwise
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — changed that line so that it now reads:
If you only want the listener to respond to messages of a certain type, you must define the listener as a non-
async
function, and return a Promise only for the messages the listener is meant to respond to — and otherwise return false or undefined
1ce9000
to
074b574
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sideshowbarker Thanks, this version seems much more clear to me. r+ from my side.
@caitmuenster do you want to give this a quick look from an editorial perspective?
This looks good to me! Thank you so much, @sideshowbarker! |
Thanks all — gonna go ahead and merge now per #3903 (comment) |
Fixes #1452