简体   繁体   中英

Javascript functions synchronous vs asynchronous

I have a webSQL database that I'm querying a good bit on pageshow/deviceready.

If I call my functions inside a pageshow like so:

$('#home').on('pageshow', function() {

request();
another();
morestill();

});

Will they be called and complete sequentially before the next one is started? Or do they happen asynchronously? I was wondering how this might affect performance? Would I be better to call the next function inside and at the end of the previous function rather than use the above? Or does this make no difference to performance?

Sorry if this is a stupid question!

The WebSQL specification defines an asynchronous database API and a synchronous database API .

If you use the synchronous API (and don't do anything else to make the function call asynchronous) then they will run sequentially.

If you use the asynchronous API, then the various bits of the three function calls will be interleaved.

The tree request are made synchronously, so before calling the next function the function before must be ended. If the request function must wait for a response of the server this time will be wasted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM