2

I encountered a practice were developers make synchronous functions asynchronous in order to make less adjustments in the future if and when the functions may change to asynchronous. What I would like to know is what is the price paid for such a practice, I assume the cost is in performance but if there is another cost I would like to know as well

const sum = async (a,b) => a + b // Made async as preparation for unknown future changes 

const someAsncFunc = async (...) => {
  ...
  const res1 = await someRealAsyncFunc(...)
  ...
  const res2 = await sum(a, b)
  ...
}
  • You can look at this question (https://stackoverflow.com/questions/56816731/what-are-the-advantages-of-using-async-await). These functions get executed as microtasks synchronously, that means that in the meantime, other asynchronous functions can be executed (onclick handler etc.). – kaffarell Dec 07 '21 at 10:15
  • I am not sure how making something asynchronous (unnecessarily) prepares you for future changes. Function that adds two numbers shouldn't be asynchronous. – Yousaf Dec 07 '21 at 11:16
  • Adding two numbers is just an example I wrote to simplify my question, their intention is that if we have a function that is used a lot and might become async in the future then to use it as async from the beginning and if needed we only change the function and don't need to rewrite all it's usages that might cause a cascading effect. I understand this is a bad practice but need help to explain the cost of this practice. – Motty Milshtein Dec 07 '21 at 11:39

0 Answers0