Re:Helidon Níma: The first Java microservices framework base...
by fnord77 on Saturday August 19, 2023 @09:04PM
(#37194987)
what are the issues with async/await?
[ Parent
| on HN ]
Re:Helidon Níma: The first Java microservices framework base...
by beders on Saturday August 19, 2023 @11:54PM
(#37195966)
the mental gymnastics.
Having fun using async/await in loops? https://zellwk.com/blog/async-await-in-loops/
An actual blocking model is much easier to grok.
Re:Helidon Níma: The first Java microservices framework base...
by saagarjha on Sunday August 20, 2023 @01:21AM
(#37196343)
Things don’t have to be that way. You can reject the use of async/await in contexts that aren’t aware of it (delegating it to special APIs that properly handle it).
Re:Helidon Níma: The first Java microservices framework base...
by mikko-apo on Sunday August 20, 2023 @03:44AM
(#37197024)
Can you elaborate? Do you mean like the Promise API with the "spesialisti APIs"?
Re:Helidon Níma: The first Java microservices framework base...
by saagarjha on Sunday August 20, 2023 @05:25AM
(#37197523)
You could have a forEach that awaits the promise created each iteration, for example.
Re:Helidon Níma: The first Java microservices framework base...
by moritzwarhier on Sunday August 20, 2023 @08:24PM
(#37204231)
This could be solved by using for..of in an asnyc function though.
It might look like surprsising behavior maybe, but putting the async keyword outside and looping without non-awaited callbacks is the only possible way to keep the semantics sound, no?
In other words, forEach would have to return a Promise too. That's where the function coloring rightfully annoys programmers to catch their mistakes, there are if cause also lint rules for this.
AFAIK there are two active proposals that aim to provide this natively (and additonaly enable working with lazy and/or infinite iterators or generator functions):
AsyncIterator and tc39/proposal-async-iterator-helpers