My app has a search function that returns JSON.
The JSON will return NULL if it's not -quite- ready and needs a few more seconds to process.
If the JSON request is returned as NULL, I need to retry every second until it's not NULL.
Here is my JS:
async search(q, callback) {
const response = await get(this.urlValue, {
query: { q: q },
responseKind: 'json'
})
if (response.ok) {
const list = await checkIfResponseNotNull();
}
function checkIfResponseNotNull() {
return new Promise(resolve => {
setTimeout(() => {
if (response.json === null) {
// Try again?
} else {
return callback(response.json)
}
}, 500)
})
}
}