Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function call inside a $.each loop, is it async or sync?

Had a debate with my colleague on this, as we had to deal with some async/sync issues. However, it raised another question, which I couldn't figure out a definite answer for.

Assume a simple for-each loop ($.each), where for-each iteration I call a function set in the global scope. Does the function run synchronously or asynchronously? Assume no Ajax, so what the function does is completely synchronous, albeit merely executed. In other words, I wonder whether the function call itself is blocking within the iteration or not.

Thanks!

like image 352
adi518 Avatar asked Jul 23 '15 23:07

adi518


1 Answers

It is synchronous. You can tell if you set a breakpoint after the loop and one inside the loop. The breakpoint in the loop will be hit before the one after the loop.

This is assuming the breakpoints will be hit in the execution, object/array being looped over has items, etc.

like image 136
DarthDerrr Avatar answered Oct 07 '22 13:10

DarthDerrr