es6-promisify

WebJar for es6-promisify

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

es6-promisify
Last Version

Last Version

5.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

es6-promisify
WebJar for es6-promisify
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/digitaldesignlabs/es6-promisify

Download es6-promisify

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/es6-promisify/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>es6-promisify</artifactId>
    <version>5.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/es6-promisify/
implementation 'org.webjars.npm:es6-promisify:5.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/es6-promisify/
implementation ("org.webjars.npm:es6-promisify:5.0.0")
'org.webjars.npm:es6-promisify:jar:5.0.0'
<dependency org="org.webjars.npm" name="es6-promisify" rev="5.0.0">
  <artifact name="es6-promisify" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='es6-promisify', version='5.0.0')
)
libraryDependencies += "org.webjars.npm" % "es6-promisify" % "5.0.0"
[org.webjars.npm/es6-promisify "5.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : es6-promise jar [4.0.3,5)

Project Modules

There are no modules declared in this project.

Travis CI

es6-promisify

Converts callback-based functions to ES6/ES2015 Promises, using a boilerplate callback function.

Install

Install with npm

npm install es6-promisify

Example

const {promisify} = require("es6-promisify");

// Convert the stat function
const fs = require("fs");
const stat = promisify(fs.stat);

// Now usable as a promise!
try {
    const stats = await stat("example.txt");
    console.log("Got stats", stats);
} catch (err) {
    console.error("Yikes!", err);
}

Promisify methods

const {promisify} = require("es6-promisify");

// Create a promise-based version of send_command
const redis = require("redis").createClient(6379, "localhost");
const client = promisify(redis.send_command.bind(redis));

// Send commands to redis and get a promise back
try {
    const pong = await client.ping();
    console.log("Got", pong);
} catch (err) {
    console.error("Unexpected error", err);
} finally {
    redis.quit();
}

Handle multiple callback arguments, with named parameters

const {promisify} = require("es6-promisify");

function test(cb) {
    return cb(undefined, 1, 2, 3);
}

// Create promise-based version of test
test[promisify.argumentNames] = ["one", "two", "three"];
const multi = promisify(test);

// Returns named arguments
const result = await multi();
console.log(result); // {one: 1, two: 2, three: 3}

Provide your own Promise implementation

const {promisify} = require("es6-promisify");

// Now uses Bluebird
promisify.Promise = require("bluebird");

const test = promisify(cb => cb(undefined, "test"));
const result = await test();
console.log(result); // "test", resolved using Bluebird

Tests

Test with tape

$ npm test

Changes from v5.0.0

  • Allow developer to specify a different implementations of Promise
  • No longer ships with a polyfill for Promise. If your environment has no native Promise you must polyfill yourself, or set promisify.Promise to an A+ compatible Promise implementation.
  • Removed support for settings.thisArg: use .bind() instead.
  • Removed support for settings.multiArgs: use named arguments instead.

Published under the MIT License.

org.webjars.npm

Digital Design Labs

Versions

Version
5.0.0