Is there a way to mix the yield generator with recursions in Vanilla Javascript ?
I have a use case really close the the code below, please don't mind the async/await as there are promises in the original.
The issue is that the following example iterates only once.
let n = 0;
async function* atGet(offset=undefined) {
if (n == 0) offset = true;
if (n < 5) yield n;
if (!!offset) {
n = n + 1;
atGet(n);
}
}
const init = async () => {
try {
for await (let n of atGet()) {
console.log(n)
}
}
catch(err) {
throw err;
}
};
init();
I'm wondering what I am doing incorrectly, any advice is welcome.