Created
January 6, 2010 04:03
-
-
Save lmorchard/270000 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = [ 1, 2, 3, 4, 5 ]; | |
var loop_cb = (function () { | |
// if the list is empty, we're finished. | |
if (0 === list.length) { finished_cb(); } | |
// get the next value from the list | |
var next_value = list.shift(); | |
// start a DB transaction | |
db.transaction(function (tx) { | |
// execute a SQL query | |
tx.executeSql( | |
"SELECT foo FROM bar WHERE baz=?", [ next_value ], | |
function (rs) { | |
// do something with the result set. | |
// ... | |
// perform the next loop iteration | |
loop_cb(); | |
}, | |
function () { | |
// something went wrong! | |
} | |
) | |
}); | |
}); | |
var finished_cb = (function () { | |
// all done with the above loop! | |
}); | |
loop_cp(); // start the loop | |
// note that code past here continues to execute before the above loop has completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment