rho-cc-node-style-callback

2.0.0 • Public • Published

rho-cc-node-style-callback

Create rho-contracts for Node-style callbacks.

Usage

You must use the Body Labs package, rho-contracts-fork:

  "dependencies": {
    "rho-contracts-fork": "^1.3.0"
  }

Use this module to create contracts for a Node-style callbacks. The returned contracts accept functions whose first argument satisfies some error contract, and the other arguments are specified the same way as c.fun.

In the Node-style callback convention, any non-null non-undefined value for the first argument indicates an error. When an error is indicated, the other arguments must not be present, else a contract error is raised.

As a special case, invoking a callback with no arguments will invoke the wrapped function with one argument set to undefined.

Calling withError on the returned contract changes the type of the error argument to the contract specified.

The main entry point of this module is withDefaultError, which sets the expected error contract, like this:

 
var c = require('rho-contracts-fork');
 
var cc = {};
 
cc.callback = require('rho-cc-node-style-callback').withDefaultError(c.error)
cc.countCallback = cc.callback({ result: c.number })

Installation

npm install rho-contracts-fork rho-cc-node-style-callback

Contribute

Pull requests welcome!

Support

If you are having issues, please let us know.

License

The project is licensed under the Mozilla Public License Version 2.0.

Readme

Keywords

none

Package Sidebar

Install

npm i rho-cc-node-style-callback

Weekly Downloads

2

Version

2.0.0

License

MPL-2.0

Last publish

Collaborators

  • gmarceau
  • paulmelnikow
  • qmaurmann