1.1.2 • Published 9 years ago

generatorify v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Build Status npm version

Generatorify

Name is a bit misleading, this package wrap a function with callback into native ES6 promise so it can be used with generators. Module is based on this gist.

Prerequests

This library works with io.js or node.js with --harmony flag. It requires native Promises and Generators.

Usage

'use strict'

const request      = require('request')
const generatorify = require('generatorify')

const requestGenerator = generatorify(request)

const load = function* () {
  let result = yield requestGenerator('http://www.google.com')

  ...
}

Test

tap test/*.js

Limitations

As mentioned above, this module requires io.js or node.js with --harmony flag. Also it works only with functions with one callback, if you have more than one, only one will be converted.