1.0.1 • Published 8 years ago

any-promisify v1.0.1

Weekly downloads
37
License
ISC
Repository
github
Last release
8 years ago

any-promise backed implementation of promisify

Installation

npm install --save any-promisify

Usage

var promisify = require('any-promisify')

// support for simple callbacks
var add = function add(a, b, cb) { cb(null, a + b) };
add = promisify(add)

add(1, 2).then(function (result) {
  console.log(result) // 3
})

// turns asynchronous functions into promised ones
var add = function (a, b) { return a + b }
add = promisify(add)

add(1, 2).then(function (result) {
  console.log(result) // 3
})

// Supports promisify the methods of an object
var obj = {
  add: function(a, b, cb) {
    return cb(null, a + b)
  },
  double: function(a, cb) {
    return this.add(a, a, cb)
  }
}

obj = promisify(obj)
obj.double(2).then(function(doubled) {
  console.log(doubled) // 4
})