3 ms·
The interesting point about this example is that an intelligent js compiler could easily rewrite this code into parallel execution. Its possible because the low
by tpetry 6y ago
The interesting point about this example is that an intelligent js compiler could easily rewrite this code into parallel execution. Its possible because the low-level await statement is declaring to wait on the execution but the calculated value is used much later first.
Maybe someone could built this for typescript, the strict typesystem should make this easily (?) solvable by some hidden wrapper type, like AwaitedButUnaccesedPromise.
- Etheryte 6y agoThe problem is it may be intentional to have the requests be sequential depending on what you're doing. It would be straightforward to identify this kind of code, but the compiler wouldn't be able to tell which was the correct business logic.
- brundolf 6y agoYes, as another commenter pointed out, this would get you into trouble if the endpoint you're calling is stateful at all. And that's definitely not something a compiler could ever reason about.
- tpetry 6y agoOh thats true, didnt think about it. But this problem could be easily solved by adding a „defer“ keyword which is basically await under the hood with the added compiler optimizations.