0.0.4 • Published 4 years ago

functions-call-chain v0.0.4

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

Functions call chain factory

How to use it?

const Chain = require('../src/Chain');
const methodsValidationError =
  new TypeError('"methods" argument must not empty be array of functions!');
let result = null;
let methods = null;

beforeEach(() => {
  result = [];
  methods = [
    (error, data, callback) => {
      if (error)
        return callback(error);

      const value = `${data} first`;

      result.push(value);

      return process.nextTick(() => callback(null, value));
    },
    (error, data, callback) => {
      if (error)
        return callback(error);

      const value = `${data} second`;

      result.push(value);

      return process.nextTick(() => callback(null, value));
    },
    (error, data, callback) => {
      if (error)
        return callback(error);

      const value = `${data} third`;

      result.push(value);

      return process.nextTick(() => callback(null, value));
    }
  ];
});

it('should execute functions in array', (done) => {

  function checkResult() {      
    expect(result.length).toEqual(3);
    expect(result[0]).toEqual('Count... first');
    expect(result[1]).toEqual('Count... first second');
    expect(result[2]).toEqual('Count... first second third');  
    done();
  }

  methods.push(checkResult);

  const chain = new Chain(methods, 'Count...');

  chain.start();
});
0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

5 years ago

0.0.1

5 years ago