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

fix: remove unnecessary return await statements #166

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

Conversation

mohit4bug
Copy link
Contributor

@mohit4bug mohit4bug commented Jun 1, 2024

There's no need to use await while returning an asynchronous function in JavaScript.

Previous:

async function example() {
  return await someAsynchronousFunction();
}

New:

async function example() {
  return someAsynchronousFunction();
}

Both code examples achieve the same result, but the second one is more concise and arguably clearer.

@mohit4bug
Copy link
Contributor Author

I noticed that the recent changes were approved but have not been merged yet. Could you please merge them when you have a moment?

@dipamsen
Copy link

dipamsen commented Jun 26, 2024

For that matter, the async declaration also becomes redundant because await keyword is not used in the function body.

// same as other versions
function example() {
  return someAsynchronousFunction();
}

Though, an argument can be made that the declaration is useful to clearly see that the function returns a promise.

@mohit4bug
Copy link
Contributor Author

mohit4bug commented Jun 27, 2024

For that matter, the async declaration also becomes redundant because await keyword is not used in the function body.

// same as other versions
function example() {
  return someAsynchronousFunction();
}

Though, an argument can be made that the declaration is useful to clearly see that the function returns a promise.

In a simple example, we use a wrapper function that returns a promise. Making it asynchronous is not necessary and should be considered. For a much simpler implementation, it's clear that using someAsynchronousFunction directly makes more sense than wrapping it with another function. Also, if it's just for naming reasons, it's fine for the function to not use any async/await statements.

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

3 participants