No description, website, or topics provided.
JavaScript
Switch branches/tags
Nothing to show
Latest commit 7c86a35 Nov 19, 2013 @sciolist 0.1.12
Permalink
Failed to load latest commit information.
test
.gitignore
LICENSE
README.md
index.js
package.json

README.md

why

Why makes working with promises, generators and node-style callback a bit less of a drag!

Requires node v0.11+ with the --harmony-generators flag!

Installation

$ npm install why

Example

var Y = require('why');
var fs = require('fs');

var stat = Y(function *(name) {
  // add Y() in place of a callback to use node-style functions.
  return yield fs.stat(name, Y());
});

var sizesOf = Y(function *(names) {
  // generators, promises, and arrays can be yielded directly.
  return yield names.map(function* (name) {
    return [name, (yield stat(name)).size];
  });
});

// Y()-wrapped generators return promises.
sizesOf(['index.js'])
  .then(function(value) { console.log(value); }) // [[ 'index.js', 3784 ]]
  .done();