rightco

0.0.4 • Public • Published

rightco

Wrap righto in a Promise, for use as a replacement for co.

Installation

npm install --save rightco righto

Note that righto is a peer dependency.

Usage

rightco(function* () {
  let foo = yield something;
  let bar = yield somethingElse;
  return {
    foo,
    bar,
  };
})
.then((result) => {
  // result: { foo, bar, }
})
.catch((err) => {
  // err: any throw or reject within something() or somethingElse()
});

Where something and somethingElse are either: a thenable, or an errback.

As such use rightco to run your generator functions, where you need them to be wrapped in a Promise.

thenable

A Promise is a thenable.

let thenable = new Promise((resolve, reject) => {
  // call either `resolve(result)` for success,
  // or `reject(error)` for failure
});

errback

Any function which has a callback function as its last parameter; and this callback function takes an error as its first parameter, and results as subsequent parameters is an errback.

let errback = function(callback) {
  // call either `callback(undefined, result)` for success,
  // or `callback(error)` for failure
};

The latter is the more interesting use case, as rightco enables the use of generator functions to yield a standard errback when wrapped with righto:

yield righto(errback);

See the test spec files for detailed usage examples.

Author

Brendan Graetz

Licence

GPL-3.0

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.4
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.4
    0
  • 0.0.3
    1
  • 0.0.2
    1
  • 0.0.1
    1

Package Sidebar

Install

npm i rightco

Weekly Downloads

3

Version

0.0.4

License

GPL-3.0

Last publish

Collaborators

  • bguiz