Are there any problems working with `return await`?

I see that there is an eslint rule no-return-await

, to denyreturn await

.

In the description of the rule, it return await

is indicated adds "extra time before the overarching Promise resolves or rejects"

.

However, when I look at the MDN async

function docs
, the "Simple Example" shows an example that contains return await

no description of why this might be a bad idea / performance issue.

Is it an return await

actual performance issue as the eslint docs suggest?

And if so, how?

+3


source to share


1 answer


No, there are no performance issues. This is just an extra additional operation. It may take a little longer, but it is hardly noticeable. It's akin to return x+0

instead return x

for an integer x

. Rather, it is exactly equivalent to meaningless.then(x => x)

.

This does no real harm, but I think this is bad style and a sign that the author is not totally agreeable and shy: hend promises and async

/ await

.

However, there is one case where it is important:



try {
    return await …;
} …

      

await

performs throws on deviations and waits for promise resolution anyway before executing catch

or finally

handlers. A simple one return

would ignore it.

+13


source







All Articles