0.1.2 • Published 9 years ago

yieldr v0.1.2

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

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