Socket
Socket
Sign inDemoInstall

nodeify

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nodeify

Convert promised code to use node style callbacks


Version published
Weekly downloads
103K
increased by1.01%
Maintainers
1
Install size
20.8 kB
Created
Weekly downloads
 

Readme

Source

Build Status

Nodeify

Convert promised code to use node style callbacks. If no callback is provided it will just return the original promise.

Installation

Server:

$ npm install nodeify

Usage

Functional

Call nodeify directly passing the promise and an optional callback as arguments. If a callback is provided it will be called as callback(error, result). If callback is not a function, promise is returned.

var nodeify = require('nodeify');

function myAsyncMethod(arg, callback) {
  return nodeify(myPromiseMethod(arg), callback);
}

Constructor / Method

The nodeify.Promise constructor returns a promise with a .nodeify method which behaves just like the functional version above except that the first argument is implicitly this.

var Promise = require('nodeify').Promise;

function myAsyncMethod(arg, callback) {
  return new Promise(function (resolver) {
    //do async work
  })
  .nodeify(callback);
}

Extend

Extend(promise)

Takes a promise and extends it to support the .nodeify method. It will still support the nodeify method after calls to .then.

var Promise = require('promise');
var nodeify = require('nodeify');

function myAsyncMethod(arg, callback) {
  return nodeify.extend(myPromiseMethod(arg))
    .nodeify(callback);
}
Extend(PromiseConstructor)

Takes a PromiseConstructor and extends it to support the .nodeify method.

var PromiseConstructor = require('promise-constructor-used-by-my-promise-method');

require('nodeify').extend(PromiseConstructor);

function myAsyncMethod(arg, callback) {
  return myPromiseMethod(arg).nodeify(callback);
}
Extend()

Extends the default promise constructor (returned by calling require('promise')) and extends it to support .nodeify.

require('nodeify').extend();

function myAsyncMethod(arg, callback) {
  //assuming myPromiseMethod uses `promise` as its promise library
  return myPromiseMethod(arg).nodeify(callback);
}

Licence

MIT

viewcount

Keywords

FAQs

Last updated on 26 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc