Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chainjs

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chainjs

Use chaining call to resolve the problem of javascript async callback handle

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

chainjs

Chaining of functions call to resolve the problem of javascript async callback handling.

Install

npm install chainjs

Usage

use in node:

var Chain = require('chainjs'),
    param = {message: 'Hello world';}

function beginStep (chain, param) {
    console.log(param.message); //Hello world
    chain.next('none');
}

function step1 (chain, data) {
    chain.next('say hello');
}

Chain(beginStep, param)
    .then(step1)
    .final(function (chain, data) {
        console.log(data); //say hello
    });

API

Chain(beginHandler)

Chain(func, param)

then(stepHandler)

Chain(func).then(func1).then(func2)

start()

Chain(func).then(func1).then(func2).start();

next(nextParams)

end(finalParams)

final(finalHandler)

data(savingData)

Saving data in current chain

Chain(function (chain, param) {
    chain.data('param', param);
    chain.next();
}, {data: ''})
    .then(function (chain) {
        var param = chain.data('param');

        console.log(param); // {data:''}
    })
    .start();

filter(filterHandler)

TBD

before(beforeHandler)

Will be invoked before each step

Chain(function (chain, param) {
    chain.data('param', param);
    chain.next();
}, {data: ''})
    .then(function (chain) { // Step 1
        var param = chain.data('param');

        console.log(param); // {data:''}
    })
    .before(function (chain) { // Step before
        console.log('It will be invoked before each chain step')
    })
    .start();

after(afterHandler)

TBD

Testing

npm test

Example

var Chain = require('chainjs');

Chain(function (chain, msg) {
        // save param
        chain.data('chain:param', msg);

        console.log(msg); //Hello world
        chain.next({message: 'Next step'});

    }, 'Hello world')
    .then(function (chain, param) {

        console.log(param.message); // Next step
        chain.end({name: 'switer'})
    })
    .then(function (chain) {
        //will be skiped
    })
    .final(function (chain, author) {
        var param = chain.data('chain:param');

        console.log(param); // Hello world
        console.log(author.name); // switer

    })
    .start(); // starting chain execute

Change Log

License

MIT

Keywords

FAQs

Package last updated on 25 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc