I have a set of async functions that issue executeSql commands to drop 2 tables, and have callbacks to create the 2 tables and populate the 2 tables.
I’d like to know when they have ALL completed.
I wouldn’t mind if they executed synchronously. In fact, I’d prefer that they ran synchronously!
Q: Would I use the jQuery pipe method to queue up these functions so that they execute in a more traditional way than issuing callbacks?
I want to do something like:
DropTableA();
CreateTableA();
PopulateTableA();
DropTableB();
CreateTableB();
PopulateTableB();
window.location.replace('Index.htm');
Have a look at jQuery’s Deferreds and Promises.
In short, here’s an example of an async function that executes something asynchronously (setTimeout in this case). When calling the function you get back a promise.
You can use $.when to execute something when all promieses have been fulfilled, i.e.
If you want to execute them in order you can chain the deferreds using the deffered’s pipe.