Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Establish convention about explicit/implicit synchronous function versions #7030

Closed
@thomseddon

Description

@thomseddon

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 supplied
  • fs: All implicitly async with explicit sync versions via corresponding *Sync() methods
  • zlib: 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions