Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Allow passing objects to util.promisify #174

@benjamingr

Description

@benjamingr

This is a proposal to extend util.promisify to accept objects in addition to promises.

Currently, a user has to type util.promisify for every function in a module they're using. This leads users to prefer userland solutions like bluebird which provide a more ergonomic method that converts entire APIs at once.

This behavior was initially planned for nodejs/node#12442 but we decided to defer it until the initial function behavior was used for a while and we saw the response.

So far the response I've received from communities I polled was generally very positive for promisify, and people often asked about the object variant.

I think now would be a good time to add it:

const fs = util.awaitable(require(fs));
async function foo() {
  const result = await fs.readFile("hello.txt"); // file contains "World"
  console.log("Hello", result);
}
foo(); // logs `Hello World`

Pinging @addaleax who wrote the code for util.promisify and did a considerable amount of design for it.

I'm posting it here for discussion about it and as a place for bikeshedding syntax or making objections for possible designs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions