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

proposal: mention that an async function has no await keyword in the function body #4948

Open
stephane-archer opened this issue Apr 21, 2024 · 4 comments

Comments

@stephane-archer
Copy link

when you modify your code, you can remove the last await in a function so the function can become synchronous but nothing tells you that and you keep await something that doesn't need to.

@lrhn
Copy link
Member

lrhn commented Apr 21, 2024

An async functions always returns a Future.
Even if you remove the last await, the function is still asynchronous. You have to change the return type too, to make it synchronous.
At that point, it's a very different function, with a different signature.

I don't see a warning if an async functions has no await as being actionable in most cases, and sometimes it's deliberate.
Will probably have too many false positives.

@stephane-archer
Copy link
Author

stephane-archer commented Apr 22, 2024

At that point, it's a very different function, with a different signature.

From my understanding, if there is no await, the function is going to execute synchronously and finish, then return a "completed future" that the caller is going to revolve immediately when he await the future.
So I don't see much difference with the Sync version except the function signature.

I see this to be deliberated when implementing an interface for example but I imagine the linter can detect if you overwrite something.

I would be happy with false positives in my case. If I can remove a bunch of await and async functions that are just async because of old await calls that are no longer there, this will make my codebase cleaner.

Remember that linters are optional and activated manually.

@lrhn
Copy link
Member

lrhn commented Apr 22, 2024

much difference ... except the function signature.

From the outside, the signature is pretty much the function. So no difference except everything about how to use the function.

It's possibly a reasonable lint while developing, if you notice that a function that you made async because it needed to be, now no longer needs to be async. It's useful during the design phase, or for private helper functions, but not for public API.
If public API returns a future, it's presumably because it intends to return a future, and returning something else is a breaking change.

@stephane-archer
Copy link
Author

@lrhn I agree with you.
if the lint applies to private helper functions, I think it's going to be a quite useful lint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants