3 ms·
I've found async to be straight forward anytime I've used it. Promise#then is equivalent to callbacks async/await often requires very little changes compared t
by __s 5y ago
I've found async to be straight forward anytime I've used it. Promise#then is equivalent to callbacks
async/await often requires very little changes compared to synchronous code, whereas reworking a program into callbacks is much more impactful. & the async/await compilation process tends to produce better performance in addition to this. My first async/await work was a few years ago to increase a data importer's performance by an order of magnitude compared to the blocking code (I also used it a couple years earlier for a GUI (PointerWare) where code would await opening new windows, it wasn't really being used for concurrency there, just a nice interface of "show pop up, wait on that view to complete" which made Back buttons easy)
Here's an example where looping made for a callback that recursively called, using async/await I get to use a plain loop:
before: https://github.com/serprex/Befunge/blob/946ea0024c4d87a1b75d808ce429442938d1770f/js/funge.js#L572 https://github.com/serprex/Befunge/blob/946ea0024c4d87a1b75d...
after: https://github.com/serprex/Befunge/blob/9677ddddb7a26b7a17ddc346be85028b0d58a767/js/funge.js#L608 https://github.com/serprex/Befunge/blob/9677ddddb7a26b7a17dd...
Callbacks make it difficult to send information up the call chain, as the caller fires it off without a ticket to wait on the result. libxcb is an example of a library which optimized on libx11 by having functions which return cookies which func_reply wait on, these functions could similarly be implemented as an async/await interface
I don't see why people find it so complicated to separate begin-compute & wait-on-compute
I've rewritten a nodejs game server into rust, https://github.com/serprex/openEtG/tree/master/src/rs/server/src https://github.com/serprex/openEtG/tree/master/src/rs/server... handleget/handlews are quite straight forward. But apparently it doesn't work
- secondcoming 5y ago> the caller fires it off without a ticket to wait on the result Exactly! Making a thread block waiting for a result isn't true async in my book. It doesn't matter that the result is going to come from another thread. Futures/Promises make you block a thread.
- __s 5y agoThat's why async/await is about having an event loop driving a state machine so that you aren't blocking a thread, you're having a state machine wait on a result Performance numbers don't care what's in your book