Remove unnecessary await
and async
keywords.
#39670
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, bothawait
keywords can be removed. Since there are no other await keywords in this function, theasync
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