3 ms·
server.getStuff(gotStuff) server.getMoreStuff(gotMoreStuff) Just using functions is more simple and also more powerful. A function being async usually mean
by z3t4 7y ago
server.getStuff(gotStuff)
server.getMoreStuff(gotMoreStuff)
Just using functions is more simple and also more powerful.
A function being async usually means stuff will happen, things can go wrong, and you might want to do different things depending on the response or whether it failed.
Where await is useful though is in serial execution of async functions that really should be sync, but them being async is an optimization in order to not block the thread.
It is really unfortunately that so much extra crud had to be introduced
to JS (corutines, async, promises) in order to be able to await.
Reading complex Promise based code is very unplesent, with async functions pretending to be pure, without any error handling, full of side effects, and omitted returns.
With callbacks we had inexperienced programmers writing pyramids of callbacks and if logic. But it was not that bad, as the complexity was in your face, and not hidden under layers of leaky abstraction.