Re:Async Iterators: These Promises Are Killing My Performance
by hetman on Sunday August 27, 2017 @11:09PM
(#15114183)
I think you've misunderstood the author's point. He would like a fast solution that also looks as simple as the Python example.
Even if you have a synchronous file read function that's doing partial file reads, you can not use it inside a synchronous loop to process the returned data because it will hold up the entire Node.js event loop until the whole file has been processed.
You can use the synchronous file read function in a way that doesn't hold up the main event loop but to do that you re-introduce all the complexity the author was trying to avoid.
Re:Async Iterators: These Promises Are Killing My Performance
by Jare on Monday August 28, 2017 @06:28PM
(#15120663)
But you CAN make a loop that looks as simple as the Python example; Python just happens to provide one built in, right? The Python code holds the thread for the entire duration just like the Node one will hold the event loop. Wouldn't the Python loop cause the same problems as the node one in an evented app, say, a Twister app? (sorry my Python is a few years rusty)
The ideal would be just as performant as the sync Python code, but effectively async. And his observation that async iterators by design can't do it without severe overhead for such tight inner loops is very good.
Re:Async Iterators: These Promises Are Killing My Performance
by abritinthebay on Sunday August 27, 2017 @10:13PM
(#15114015)
Right, exactly. Very well put :)
(I assume there are 100s of npm packages that do this already)