npm

Need private packages and team management tools?Check out npm Orgs. »

yieldr

0.1.2 • Public • Published

yieldr

NPM version Dependency Status Travis CI Coveralls

Installation

npm install yieldr

Usage

var yieldr = require('yieldr')
 
function* bar () {
  return Promise.resolve('bar')
}
 
yieldr(function* () {
  var foo = yield 'foo'
  var bar = yield bar()
 
  return foo + bar
}).then(function (res) {
  console.log(res) // 'foobar'
})

Yieldables

You can yield anything just like native yield.

yieldr(function* () {
  var foo = yield 'foo'
  var isTrue = yield true
  var zero = yield 0
})

But yieldr will try to resolve these types:

  • Promises
  • Generators and generator functions
var fs = require('mz/fs')
 
yieldr(function* () {
  var content = yield fs.readFile(FILE_PATH)
})

Note: there is a yield* expression in ECMAScript 6, and it's designed for delegating to another generator or iterable object.

Compatibility

yieldr requires Promise, you should use node >=0.11.9 or include a polyfill (try bluebird).

Contributors

Via GitHub

install

npm i yieldr

Downloadsweekly downloads

7

version

0.1.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability