I have an endpoint that generates some data (it takes some time) and another one that I can use to get the generated data. I call first one with await, take id from response, and want to call second one, while it status don't be "Success"(it mean data prepared and stored in response) and continue my script.
Here my code
let data = ['foo', 'bar']
let res = await client.post('ninbexec/v2/executions', data)
let result_id = res.data[0].id
while (true) {
let resp = await client.get(`ninbexec/v2/executions/${result_id}`)
if (resp.data.status === 'SUCCEEDED') {
response = JSON.parse(resp.data.result.dataset)
break;
}
}
it works, but I won to so much requests how can I set up some interval for requests? I tried with await setInterval(), but code continue execution and not wait for result
e.g. also I use axios, if it have some ballet in trick for that it will be more better