Skip to content
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

refactor: add no-return-await lint rule #4384

Merged
merged 3 commits into from
Mar 16, 2020

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju requested a review from ry March 15, 2020 16:54
Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, awesome...

When await is not used in the method/function block, does async cause another microtask to be scheduled? Either way, if you are returning a promise in all branches (like a lot of these updates) the method no longer needs to be async. There is an eslint rule of require-await which would catch this as well. With TypeScript checking the return type it is very unlikely enforcing this would cause incorrect behaviour.

@bartlomieju
Copy link
Member Author

LGTM, awesome...

When await is not used in the method/function block, does async cause another microtask to be scheduled?

Not sure, but thanks for the lead.

Either way, if you are returning a promise in all branches (like a lot of these updates) the method no longer needs to be async. There is an eslint rule of require-await which would catch this as well. With TypeScript checking the return type it is very unlikely enforcing this would cause incorrect behaviour.

I'll see to it tomorrow

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Mar 15, 2020

Either way, if you are returning a promise in all branches (like a lot of these updates) the method no longer needs to be async

Hmm, isn't it a good indicator for a function that returns a Promise to be marked async? Or does it affect performance? (I guess I disagree with "either way".)

EDIT: After playing around a bit, no async is noticably faster 100% of the time. Nevermind it's all the same.

@kitsonk
Copy link
Contributor

kitsonk commented Mar 15, 2020

Hmm, isn't it a good indicator for a function that returns a Promise to be marked async?

It is an internal concern, it has no external detectable difference... When you generate a type definition for example, there is no indication that the method is async or not.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - great!

}

/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */
async function write(rid, data) {
return await sendAsync(ops["write"], rid, data);
return sendAsync(ops["write"], rid, data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be interesting to see if this has any effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should. It is at least one less microtask, unless V8 optimises it out, which it might be smart enough to do.

@bartlomieju bartlomieju merged commit 1edb20b into denoland:master Mar 16, 2020
@bartlomieju bartlomieju deleted the remove_return_await branch March 16, 2020 09:22
@bartlomieju
Copy link
Member Author

There is an eslint rule of require-await which would catch this as well. With TypeScript checking the return type it is very unlikely enforcing this would cause incorrect behaviour.

@kitsonk I did a quick check and we'd have to add a lot of supressions to tests (because there's a lot of mocks that assert async functions were called). I'm open to that change, but I'd open a new issue for that.

caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants