-
Goal: I'm attempting to write a JS query that loops through paginated api calls until there are no new pages in the list
-
Steps: I've tried using promise chains, then chains, on success chains. All of the asyncronicty is leading to inconsistent results. Sometimes it only returns the first page, sometimes the second, never all the pages.
-
Code:
await getFonts.trigger()
let data = getFonts.data
let availableFonts = new Map()
while(data.next){
let tick = true
getMap(availableFonts, data.items)
//Find the next chunk of data to request from the api, regex to pull the values I want
let load = data.next.replace(RegExp("^[^_]*="), '')
await setFontLimit.trigger({additionalScope:{limit: load},
onSuccess: getFontsByLimit.trigger({
onSuccess: x => { data = x; console.log(x); tick = false}})})
//wait until success
while(tick){
console.log("tickticktick")
await new Promise(resolve => setTimeout(resolve, 1000))
}
}
console.log(JSON.stringify(availableFonts))
return availableFonts