DEV Community

Discussion on: Don't make that function async.

Collapse
 
nicolasini profile image
Nico S___

I see async/await being used as a way to write "cleaner" code a lot, to make it "flatter". But same deal with promises. We write them to wait for something that is async, but our code doesn't do anything else until is done. We might release the thread to deal with other calls (think of an API), but the current call is being dealt synchronously.
I'm yet to see an example where either promises, callbacks, or async/await are used to wait for some "side effect" but the current execution continues to do something useful while it waits...

Collapse
 
clovis1122 profile image
José Clovis Ramírez de la Rosa • Edited

Yo Nic,

Async/await looks beautiful when it's done in that way (to make async code look and feel as if it was sync). It makes it easier to deal with.

I think that starting long async functions as early as possible is a great idea. Sadly I don't have any straightforward example about starting a long process while still doing something useful with the current execution. When you do it, it's usually just firing and waiting for other async requests.

Occasionally on the Client, we fire a request to get/save some data, save the request promise in a variable, and perform some small checks before launching an UI update event. At the end we await the request to launch another UI update event with the outcome (success/failure).

Collapse
 
emkographics profile image
Emko

word up!