DEV Community

Discussion on: Why async code is so damn confusing (and a how to make it easy)

Collapse
 
jochemstoel profile image
Jochem Stoel

My bad, I should have seen that.

Intrigued. I have a strongly opinionated post draft saved that is spooky similar to what I read from you today. Asking the same questions providing the same examples. I will have a more interested look at your emoji package and the patterns you are adopting.

Thread Thread
 
joelnet profile image
JavaScript Joel

I'm guessing you are like me and have about a dozen articles in the 90% finished draft state?

Can't wait to see what you are working on!

Thread Thread
 
jochemstoel profile image
Jochem Stoel

Although the notation would not be identical. Another thing you can do is write a single function to handle both sync and async and deciding which by its arguments. Asynchronous if a callback is provided, otherwise synchronous.

/* synchronous return */
readFile('file.txt')

/* asynchronous, no return value */
readFile('file.txt', console.log)