Why there's no await when calling find methods?
See original GitHub issue(It’s not an issue, just a question)
Why there’s no await
when calling find
methods?
for example:
const getUserById = async (id) => {
return User.findById(id); <-- no await
};
or:
const getUserByEmail = async (email) => {
return User.findOne({ email }); <-- no await
};
I thought that maybe the rationale was: “no await before mongoose methods”, but it can’t be that, because there is an await
before other mongoose methods, such as create
, for example:
const createUser = async (userBody) => {
if (await User.isEmailTaken(userBody.email)) {
throw new ApiError(httpStatus.BAD_REQUEST, 'Email already taken');
}
const user = await User.create(userBody); <-- has await
return user;
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Because this call is not awaited, execution of the current ...
Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the Await operator ...
Read more >Finding Async Method Calls Missing Await - .NET Core Tutorials
Consider applying the 'await' operator to the result of the call. The problem with this is that the warning isn't always immediately noticeable....
Read more >Is possible to call async function without await keyword? and ...
Call an async function without await and you will get a promise as the return value. Code following the await will execute immediately....
Read more >Calling .NET Methods With and Without Async
Using the await keyword launches the method (and any code that follows it in the calling method) on a separate thread. When the...
Read more >no-return-await - ESLint - Pluggable JavaScript Linter
Using return await inside an async function keeps the current function in the call stack until the Promise that is being awaited has...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@turanibrahim That will work too 😃 but consult link referenced in @Sicria’s reply.
It’s unfortunate that this issue was closed, as my question wasn’t really answered. The answers here justify what happens in
getUserById
(which has noawait
), but then - by the same rationale - shouldn’t theawait
increateUser
(which has anawait
) be removed?