Thursday 3 May 2018

CallBack Methods are really amazing when working in asynchronous ennvironment ..

I have done some work in javascript and when i was woking with asynchronous calls i was in big trouble because :

# i was using that  result (r) from a asynchronous call  in some other function (f) and the problem was that -

 function (f)  was running before (r) was getting result from a asynchronous call.


# the same problem i faced when getting result with Google API.







                                     But          Then         Whoooa.......


Every problem solved by just using JavaScript Callabck Function.

because the callback function runs only when it is getting the actual result from asynchronous calls and you can get results from that function easily , where you need , is it not simple ?????.


So use callbacks when using asynchronous calls.


Here are some links when you can read about javascript callback functions :


https://developer.mozilla.org/en-US/docs/Glossary/Callback_function

#https://medium.com/codebuddies/getting-to-know-asynchronous-javascript-callbacks-promises-and-async-await-17e0673281ee   

https://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function