javascript - Control flow of an IF statement & Asynchronous function -


my code structured follows:

if (something) { ..stuff ..asynchronous function call } else (something) { ..stuff ..asynchronous function call } ..more stuff 

let's if condition met, code executes 'stuff', moves onto asynchronous function call. simple call out of if statement , execute 'more stuff' in mean time on assumption of waiting asynchronous function call finish?

or

does finish waiting asynchronous function call finish executing, continue 'more stuff' normal if statement block do.

in prior case, advice on how ensure asynchronous function call finished before exits if block?

** note, i've included more stuff inside both asynchronous function calls ensure calls done before moves on, feel bad programming because if had 50 elif's, have copy paste code 50 times opposed putting @ end of if statement.

thank provided!

you can approach , less painfully using javascript promises. have following links:

the basic idea of javascript promises use of asynchronous calls can executed in order. this:

$.when(get_products).then(  if_success  else ).fail(  show message  clean because wrong happened ).done(  clean because went okay ) 

with that, can make code more maintainable. not easy grasp @ beginning, give try, save lot of headaches!


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -