I need to use await in a response function, but I couldn't figure out how.
(Note: func2() is an async function)
async function get_data() {
for (i = 0; i < 10; i++) {
// http request, returns json...
await func1(data1, data2).then(json => {
if (json.value < 100) {
await func2(); //error => await is only valid in async function
}
})
}
}
I have to wait for func2, how can I do that?
I tried this:
async function get_data() {
for (i = 0; i < 10; i++) {
await func1(data1, data2).then(json =>
async function() { // nothing happens, function doesnt work.
if (json.value < 100) {
await func2();
}
})
}
}