Skip to content

Remove unnecessary await and async keywords. #39670

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

qdirks
Copy link
Contributor

@qdirks qdirks commented May 25, 2025

process.stdout.write does not return a promise, it returns a boolean indicating whether it's okay to keep writing or if you should wait for the drain event (true indicates okay to keep writing). Since there's no promise to await, both await keywords can be removed. Since there are no other await keywords in this function, the async keyword can also be removed. Since the function no longer awaits the first write, this fixes a bug where multiple unawaited calls to sendMessage would cause only the header to be written over and over as each call hits the first write call, but then waits for the next process tick to do the second write call, causing a bug.

Description

Remove unnecessary keywords which may mislead readers who are attempting to adapt the code.

Motivation

Removing the await keywords makes the code more robust, as multiple unawaited calls to sendMessage will do the correct thing by sending each message over to the extension side, instead of writing the header over and over. It helps readers to not struggle so much trying to figure out why it isn't working.

Additional details

https://nodejs.org/api/stream.html#writablewritechunk-encoding-callback

Related issues and pull requests

`process.stdout.write` does not return a promise, it returns a boolean indicating whether it's okay to keep writing or if you should wait for the drain event (`true` indicates okay to keep writing). Since there's no promise to await, both `await` keywords can be removed. Since there are no other await keywords in this function, the `async` keyword can also be removed. Since the function no longer awaits the first write, this fixes a bug where multiple unawaited calls to sendMessage would cause only the header to be written over and over as each call hits the first write call, but then waits for the next process tick to do the second write call, causing a bug.
@qdirks qdirks requested a review from a team as a code owner May 25, 2025 11:29
@qdirks qdirks requested review from rebloor and removed request for a team May 25, 2025 11:29
@github-actions github-actions bot added Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed labels May 25, 2025
Copy link
Contributor

github-actions bot commented May 25, 2025

Preview URLs

(comment last updated: 2025-05-27 08:59:26)

@qdirks qdirks marked this pull request as draft May 25, 2025 11:47
@qdirks qdirks marked this pull request as ready for review May 26, 2025 03:15
@rebloor rebloor requested a review from dotproto May 26, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant