New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve "no-constant-condition" rule for generators #8566
Comments
So basically, my take on it is this:
So I think this merits revisiting, and I will 👍 this enhancement. |
This is incorrect -- when generator functions use |
@not-an-aardvark that is a good point. I guess we should limit this to just generator for now then and discuss async functions at a later point. |
@not-an-aardvark function delay(ms) {
const promise = new Promise(resolve => {
setTimeout(() => resolve(), ms)
})
return promise
}
async function backoff(i = 0) {
while (true) {
console.log(i++)
await delay(i * 1000)
}
}
backoff() |
@Andarist the promise returned from backoff() will never resolve which doesn't seem like good API design 🤔 |
Hm. I guess... although i dont see this as such bad design if somebody really needs an infinite task |
@Andarist My take on that is, just like for infinite loops, Infinite generators, on the other hand, are a completely different animal altogether and I think we should consider enhancing So with all that said, I think I lean towards an exception for generators only. |
// background worker
(async () => {
while(true) {
await delay(15 * 1000);
updateStockPrices();
}
})(); That is, global "background work". That said, the above code can be rewritten as: setInterval(updateStockPrices, 15000); On the other hand - async generators should definitely be supported (functions that are both async and generators). |
@eslint/eslint-team We have 3 👍s for this proposal, so we just need a team member to champion it so we can accept it. |
I'll champion if we're okay with restricting this to generators for now (and if @Turbo87 is willing to modify the original post and issue title accordingly to avoid confusion). That means we would need one more 👍 from the team since I'm currently one of the three. |
@platinumazure I've updated the title and post. Thanks for the reminder :) |
If possible, can I take on this issue? |
@VictorHom Please feel free - and thank you! |
…lint#8566)" This reverts commit 7bcd3cc.
This topic has been discussed already in #1299 and #2375 but per #2375 (comment) I'm opening a new issue for this.
#2375 (comment) has introduced a proposal for handling this which seems pretty reasonable:
Bad:
Bad:
Good:
It should be noted that the same should also apply to async functions which have roughly similar semantics. Since both generators and async/await are starting to be adopted a lot more this topic should be revisited./cc @platinumazure
The text was updated successfully, but these errors were encountered: