DEV Community

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

 
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)