I have this code:
for await (const thing of signal()) {
// logic
}
for await (const thing of anotherSignal()) {
// logic
}
The problem is that these for awaits run forever. So the second one never executes. Is there a way to make these 2 loops run in parallel?
Don't wait for first task to complete, Run them parallel, Like So:
let delay = ms => new Promise(ok => setTimeout(ok, ms));
async function* infinit_iter() {
for (let i = 0;; i++) {
await delay(3000)
yield i
}
}
async function run(name, iter) {
for await (let i of iter)
console.log(name, i)
}
run("signal:", infinit_iter())
run("anotherSignal:", infinit_iter())