Establish convention about explicit/implicit synchronous function versions #7030
Description
I think there is a level of inconstancy in the current API with regards to the use of async/sync. In some places, async and sync version of functions are separate with async being default, in other places sync is default, in other async/sync can be implicitly implied depending on whether a callback is supplied.
Firstly, an overview of the current state:
crypto
: All implicitly synchronous except pbkdf which is async by default but offers an explicit *Sync() version and randomBytes() where sync/async is implied depending on if a callback is suppliedfs
: All implicitly async with explicit sync versions via corresponding *Sync() methodszlib
: Now, implicitly async/sync depending on if callback is supplied
Other modules, such as dns
, http
, net
, os
, path
etc. are all implicitly sync or async and either do or do not accept a callback.
This was briefly brought up in #6987 and subsequently #7028 but I would like to nail this once and for all across all API's and have a definitive convention if possible?
Personally, I am in favour of depreciating all the explicit *Sync() functions and converging on a convention of async/sync being implicitly implied based on if a callback is supplied. Users would know if a function has async/sync versions based on if a callback is or isn't used respectively. Also, if a callback is not an option, it's always sync. Conversely, if it is required, it's always async with no sync option.
This would be relatively easily integrate into current fs
module and would a solid convention moving forward?