I'm having issues with this block of code while attempting to make it non-blocking.
The code is intended to wait for an undefined variable to be assigned in a non-blocking manner. I have attempted using the statements in the if block without success.
The issues I'm having are;
- Program does not wait (await) until the checkInputCoinStatus() function is done
- The whole program ends unexpectedly after the variable has been set
I would like to wait for the for all processes within checkInputCoinStatus() to be finished before proceeding inside a main function that is asynchronous.
async checkInputCoinStatus() {
// while (true) {
// if (this.selectedCoin) {
// break;
// }
// await new Promise((r) => setTimeout(r, 1));
// }
const getSelectedCoin = () => {
return this.selectedCoin
}
await (async function codeBlock() {
const selectedCoin = getSelectedCoin()
if (selectedCoin === undefined) {
// setTimeout(async () => {await codeBlock()}, 0)
// await new Promise(() => setTimeout(async () => {await codeBlock()}, 0));
// await new Promise(() => setTimeout(codeBlock, 0));
}
})();
}
Thank you.