Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zeitgeist Borders - Data Collection
function mkAllQueries(query) {
var allRes = {}
var promises = []
for (var i = 0; i < nb_hls; i++){
promises.push($.getJSON(apiUrl, {
"client": "firefox",
"hl": hls[i],
"q": query
})
.done(function (hl, q) {
return function (data) {
allRes[hl] = data
}
}(hls[i], query, allRes))
.fail(function (error) {
console.log(error)
})
.always(function () {
console.log("Completed.")
})
)
}
$.when.apply($, promises)
.done(function (data) {
allRes = formatRes(allRes)
doYourThing(allRes)
})
.fail(function (error) {
console.log(error)
})
.always(function () {
console.log("AllCompleted.")
})
}
function doYourThing(allRes) {
console.log(allRes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment