Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Does awaiting a non-Promise have any effect on performance?

Lets say I have this function

function sendMessage(message, content) {
  return message.send(content);
}

message returns a promise, but I don't actually need to resolve the promise as I don't care for the returned value.

In another async function, I call sendMessage as follows:

await sendMessage(message, 'Hello')

vs

return sendMessage(message, 'Hello')

The async function which am I calling this in is being awaited at the top level.

My question is what is the difference between me await vs returning, as the sendMessage function is not async and I don't need the returned value. What would be faster in terms of a more efficient for performance and event loop speed, if at all there even is a difference? Thanks!

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

There isn't a performance difference between the two; If you don't need use the value of the resolved promise, you shouldn't be using return or await.

about 4 years ago · Santiago Gelvez Report

0

As mozilla official docs mentioned:

An async function is a function declared with the async keyword, and the await keyword is permitted within it. The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains.

The body of an async function can be thought of as being split by zero or more await expressions. Top-level code, up to and including the first await expression (if there is one), is run synchronously. In this way, an async function without an await expression will run synchronously. If there is an await expression inside the function body, however, the async function will always complete asynchronously.

On the other word, we usually use async functions and await keyword mostly to avoid promise chaining (promise.then() multiple times, which make our code really messy and unreadable) when running multiple promises synchronously. Since your code contained only one promise only, basicly await-ing the promise to fullfil or return it directly will be the same.

about 4 years ago · Santiago Gelvez Report

0

async/await just is syntactic sugar,await need use with async otherwise it will throw a error,and it will transform it to a promise,promise are async non-promise are sync,it will affect thread execute order.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!