So, my function looks like so
async function* doIt(arr){
let counter = 0;
while(true) yield arr[counter++];
}
(async() => {
let arr = [1,2,3];
let x = doIt(arr);
setTimeout(() => {arr.push(4)}, 3000);
await x.next();
await x.next();
await x.next();
await x.next(); //I want to pause here until 4 has arrived, instead, got undefined
})()
I was hoping await
here would cause doIt
to pause after 3
until 4
has arrived. how can I achieve this? is this doable? I need the program not halted while waiting for 4
Thanks