Never-ending Pumpkin Mulch

    rho-cc-promise

    4.0.0 • Public • Published

    rho-cc-promise

    version license build code style

    Create rho-contracts for Promises.

    Usage

    Use with @rho-contracts/rho-contracts:

      "dependencies": {
        "@rho-contracts/rho-contracts": "^3.0.0"
      }

    Use this module to create contracts for promises. The returned contracts check the values of resolve and optionally reject, propagating contract errors through reject.

    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 a mixin, which extends c.fn and c.fun to return contracts with returnsPromise methods.

    const c = require('rho-cc-promise').mixin(require('rho-contracts-fork'))
     
    const cc = {}
     
    cc.info = c.object({ data: c.any })
     
    cc.getInfo = c.fun().returnsPromise(cc.info)
     
    // A function which returns a promise which resolves with no value.
    cc.doSomething = c.fun().returnsPromise(c.value(undefined))
     
    // A function which returns a promise which rejects with a custom error type.
    cc.customError = c.array(c.error)
     
    cc.doSomething = c
      .fun()
      .returnsPromise(c.value(undefined))
      .withError(cc.customError)

    It's compatible with most promise implementations, including ES6 Promise and implementations which adhere to A+.

    Installation

    npm install rho-contracts-fork rho-cc-promise

    Contribute

    Pull requests welcome!

    License

    The project is dually licensed under the Mozilla Public License Version 2.0, and the MIT license. You may use either one, at your option.

    Install

    npm i rho-cc-promise

    DownloadsWeekly Downloads

    3

    Version

    4.0.0

    License

    (MPL-2.0 OR MIT)

    Unpacked Size

    23.7 kB

    Total Files

    6

    Last publish

    Collaborators

    • paulmelnikow