DEV Community

Discussion on: Converting to Asynchronous Code Using IIFEs

Collapse
 
chico1992 profile image
chico1992

Why go through all the trouble of writing those IIFE’s instead of simply calling func3?

Collapse
 
thomasstep profile image
Thomas Step

Good question. I tried to clarify that in the post, but obviously did not do a great job.

Again, try to think of each function that I am calling in the IIFEs as being multiple statements long and not simply a function.

The code snippets were more just to illustrate making async IIFEs work with Promise.all, not necessary the purpose of those IIFEs that I wrote. Otherwise you're totally right, you might as well just call the function. If you can imagine taking 20 lines of statements or calculations and replacing func3 with those, then it would make more sense. I just didn't want to write out those 20 lines 😂

Collapse
 
chico1992 profile image
chico1992

To be honest I still don’t get it, if i understand you correctly I should imagine replacing the body of every IIFE with like 20 lines of code
That would amount to 60-80 lines of code inside the Promise.all
Maybe you have a more concrete example to explain