apihub icon indicating copy to clipboard operation
apihub copied to clipboard

fix: remove unnecessary return await statements

Open mohit4bug opened this issue 1 year ago • 3 comments

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 avatar Jun 01 '24 12:06 mohit4bug

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

mohit4bug avatar Jun 23 '24 07:06 mohit4bug

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.

dipamsen avatar Jun 26 '24 08:06 dipamsen

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.

mohit4bug avatar Jun 27 '24 10:06 mohit4bug

I agree with you @mohit4bug but keeping it in codebase does not affect the logic. However, we will consider this refcator PR in the future while we revamp the code and address some logical as well as compatibility issues. Thank you! Closing for now

wajeshubham avatar Oct 02 '24 09:10 wajeshubham