Giter VIP home page Giter VIP logo

util.promisify's Introduction

util.promisify

Polyfill for util.promisify in node versions < v8

node v8.0.0 added support for a built-in util.promisify: nodejs/node#12442

This package provides the built-in util.promisify in node v8.0.0 and later, and a replacement in other environments.

Usage

Direct

const promisify = require('util.promisify');
// Use `promisify` just like the built-in method on `util`

Shim

require('util.promisify/shim')();
// `util.promisify` is now defined
const util = require('util');
// Use `util.promisify`

Note: this package requires a native ES5 environment, and for Promise to be globally available. It will throw upon requiring it if these are not present.

Promisifying modules

If you want to promisify a whole module, like the fs module, you can use util.promisify-all.

util.promisify's People

Contributors

adamvoss avatar exe-boss avatar ljharb avatar merceyz avatar simenb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

util.promisify's Issues

Please drop deprecated __proto__ calls

Hi,

here is a simple patch to do this:

--- a/implementation.js
+++ b/implementation.js
@@ -4,7 +4,7 @@

 var isES5 = typeof Object.defineProperty === 'function';

-var hasProto = [].__proto__ === Array.prototype; // eslint-disable-line no-proto
+var hasProto = Object.getPrototypeOf([]) === Array.prototype

 if (!isES5 || !hasProto) {
        throw new TypeError('util.promisify requires a true ES5 environment, that also supports `__proto__`');
@@ -75,7 +75,7 @@
                });
        };

-       promisified.__proto__ = orig.__proto__; // eslint-disable-line no-proto
+       Object.setPrototypeOf(promisified, orig.__proto__);

        Object.defineProperty(promisified, kCustomPromisifiedSymbol, {
                configurable: true,

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Add support for multiple values resolution

const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function lsExample() {
  const { stdout, stderr } = await exec('ls');
  console.log('stdout:', stdout);
  console.log('stderr:', stderr);
}
lsExample();

It is my understanding that the above example does not work.

Too many dependencies :(

β”‚   β”œβ”€β”¬ [email protected]
β”‚   β”‚ β”œβ”€β”¬ [email protected]
β”‚   β”‚ β”‚ └── [email protected]
β”‚   β”‚ └─┬ [email protected]
β”‚   β”‚   β”œβ”€β”€ [email protected] deduped
β”‚   β”‚   └─┬ [email protected]
β”‚   β”‚     β”œβ”€β”¬ [email protected]
β”‚   β”‚     β”‚ β”œβ”€β”€ [email protected] deduped
β”‚   β”‚     β”‚ β”œβ”€β”€ [email protected]
β”‚   β”‚     β”‚ └─┬ [email protected]
β”‚   β”‚     β”‚   └── [email protected] deduped
β”‚   β”‚     β”œβ”€β”€ [email protected]
β”‚   β”‚     β”œβ”€β”¬ [email protected]
β”‚   β”‚     β”‚ └── [email protected] deduped
β”‚   β”‚     β”œβ”€β”€ [email protected]
β”‚   β”‚     β”œβ”€β”€ [email protected]
β”‚   β”‚     β”œβ”€β”¬ [email protected]
β”‚   β”‚     β”‚ └── [email protected] deduped
β”‚   β”‚     β”œβ”€β”€ [email protected]
β”‚   β”‚     β”œβ”€β”€ [email protected] deduped
β”‚   β”‚     β”œβ”€β”¬ [email protected]
β”‚   β”‚     β”‚ β”œβ”€β”€ [email protected] deduped
β”‚   β”‚     β”‚ └── [email protected] deduped
β”‚   β”‚     └─┬ [email protected]
β”‚   β”‚       β”œβ”€β”€ [email protected] deduped
β”‚   β”‚       └── [email protected] deduped

This seems massively overkill for util.promisify which already depends on ES5 and global.Promise ;

We should be able to remove all these dependencies and make this a lightweight module.

"promisify" property

so that we can destructure the same as we would using "util":

const {promisify} = require('util');
const {promisify} = require('util.promisify');

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): true

Node 7.7.4
Windows 10

functions that returns true are rejected?

require('util.promisify/shim')();
const util = require('util');

const exists = util.promisify(fs.exists); 
async function test() {
    await exists("path_to_an_existing_file");
}
test();
(node:109376) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): true

Need to patch the standard library

Hey,

Thanks for the polyfill!

util.promisify doesn't only add the custom promisify argument - it also patches the standard library methods with a custom promisification property. This is useful for things like fs.exists.

An in-range update of es-abstract is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency es-abstract was updated from 1.17.4 to 1.17.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

es-abstract is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 5 commits.

  • 3641bbb v1.17.5
  • bdd77b5 [Fix] CreateDataProperty: update an existing property
  • 920a682 [Dev Deps] update make-arrow-function, tape
  • b9069ac [Fix] run missing spackle from cd7504701879ddea0f5981e99cbcf93bfea9171d
  • 9f1690f [Dev Deps] update @ljharb/eslint-config

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Illegal invocation error thrown when trying to use promisified function

const promisify = require("util.promisify")
var sqlite3 = require("cross-sqlcipher")
var db = new sqlite3.Database("testdb")
const exec = promisify(db.exec)
var promise = exec("PRAGMA KEY=\"ABCDEFG\"")

(node:13872) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Illegal invocation

An in-range update of auto-changelog is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The devDependency auto-changelog was updated from 1.16.2 to 1.16.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

auto-changelog is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

shim.js: duplicate code?

Delete the first of the following two lines?

util.promisify = polyfill;
Object.defineProperty(util, 'promisify', { value: polyfill });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.