I'm working with an api to do an async upload, but the api does not use promises so I can't easily do an await on it. The api calls an onComplete callback instead.
My functions look something like this:
let barStatus = "not started";
fun doAsyncBar() {
barStatus = "loading";
// do something async
}
fun onBarFinished() {
barStatus = "finished";
}
async isBarFinished() {
while(barStatus != "finished") {
await sleep(10)
}
return true;
}
async foo() {
const bar = doAsyncBar();
const barFinished = await isBarFinished();
// do something else
}
My current code works, but I'm curious what would be the best practice for this scenario. Thank you!