Wondering what’s next for npm?Check out our public roadmap! »

    catchy

    1.0.3 • Public • Published

    catchy NPM version Build Status Dependency Status

    Promise-like async parallel control flow library, without so much abstraction.

    Install Nodei.co stats

    Install with npm

    $ npm install catchy
    

    API

    catchy(fns(value[, [resolve[, reject]]), end(err, res))

    • fns {Array} with async/sync functions
      • value {Anything} that are from previous function's .resolve
      • resolve {Function} that send some value to next function .resolve('value for next fn')
      • reject {Function} that throw some error to end .reject(new Error('some err'))
    • end {Function} function that will be called when error (rejected), or complete successful
      • err can be intanceof Error or message provided from .reject

    Usage

    Some example, also see example.js. Try to fail it to see behaving. :)

    var catchy = require('catchy')
    var first = 'str';
    catchy([
      function then1(resolve, reject) {
        if (typeof first == 'string') {
          console.log('1 [pass] $first is `string`')
          resolve(first+123)
          return;
        }
        reject(new TypeError('1 [fail] $first must be `string`'))
      },
      function then2(data, resolve, reject) {
        if (data == 'str123') {
          console.log('2 [pass] $data is `str123`')
          setTimeout(function() {
            resolve([data, 123, true])
          }, 500)
          return;
        }
        reject(new Error('2 [fail] $data must be `str123`'))
      },
      function then3(data, resolve, reject) {
        if (Array.isArray(data) && data.length == 3) {
          console.log('3 [pass] $data is `array`')
          console.log('3 [pass] $data is with length 3')
          resolve(data);
          return;
        }
        reject(new Error('3 [fail] $data must be array with length 3'))
      },
      function then4(data, resolve, reject) {
        if (data[1] !== 123) {
          reject(new Error('4 [fail] $data[1] should be `123` {Number}'))
          return;
        }
        setTimeout(function() {
          console.log('4 [pass] $data[1] is `123`, convert to `yes123`')
          data[1] = 'yes123'
          resolve(data, 'hello here')
        },200)
      },
      function then5(data, second, resolve, reject) {
        if (data[1] === 'yes123' && second === 'hello here') {
          console.log('5 [pass] $data[1] is `yes123`')
          console.log('5 [pass] $second is `hello here`')
          resolve(12, data, second)
          return;
        }
        reject(new Error('5 [fail] $data[1] should be `yes123` {String} and $second should be `hello here`'))
      }],
    function done(err, res) {
      if (err) {
        console.error(err)
        return;
      }
      console.log('Completed successfully!');
      console.log(res)
    })
     

    Tests

    As usual - npm test or if you have mocha globally - mocha.

    $ npm test
    

    Authors & Contributors author tips

    Charlike Mike Reagent

    License MIT license

    Copyright (c) 2014 Charlike Mike Reagent, contributors.
    Released under the MIT license.

    Install

    npm i catchy

    DownloadsWeekly Downloads

    1

    Version

    1.0.3

    License

    none

    Last publish

    Collaborators

    • avatar
    • avatar