GithubHelp home page GithubHelp logo

runnerjs's Introduction

RunnerJS

RunnerJS aims to make it easier and more readable to run chains of async functions. This can be useful when doing data processing that involves async operations like database queries/writes, and file/network operations.

run()

RunnerJS runs a series of functions, passing the results of each function on to the next in the chain. Chains can also been seeded.

var runner = require( 'runnerjs' ).make();
runner.run([
        function( next, seed ) { next(null,'foo'); },
        function( next, foo ) { next(); },
    ],
    function(err) {
        // chain finished, maybe with error
    },
    [ 'seed argument' ]
);

Each function receives a reference to the next function in the chain, and some arguments. The functions should call the next() method when they are done, giving it the standard error object as the first argument and then some arbitrary parameters.

The second argument to run() is the completion function. This will be called either then the last function in the chain completes, or when an error occurs.

map()

You can also use the map method to map a function onto an array, and execute async code on each callback. Any function returning an error stops the chain.

runner.map(
    [ 1, 2, 3 ],
    function( callback, data ) {
        // ...
        callback();
    },
    onComplete
);

The completion function fires either at the end of the chain, or when the first error occurs. Each function in the chain should use the callback passed in to carry on the chain, giving an error as the first argument if something went wrong.

Installation

RunnerJS can be installed through NPM.

npm install runnerjs

runnerjs's People

Contributors

rodnaph avatar

Stargazers

Owain Lewis avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.