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

cjs-async

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cjs-async

Asynchronous tools.

  • 1.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
388
decreased by-11.82%
Maintainers
2
Weekly downloads
 
Created
Source

Asynchronous tools

build status npm version dependencies status devDependencies status Gitter RunKit API

Set of methods to synchronize asynchronous operations.

Installation

npm install cjs-async

Usage

parallel

Run the tasks array of functions in parallel, without waiting until the previous function has completed. If any of the functions pass an error to its callback, the main callback is immediately called with the value of the error. Once the tasks have completed, the results are passed to the final callback as an array and hash. Task function name is used to name the corresponding hash-table values. Task function can either use callback to specify error and result value or return result value immediately.

Online example:

var parallel = require('cjs-async/parallel'),
    taskList = [
        function ( callback ) {
            setTimeout(function () {
                callback(null, true);
            }, 10);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, 256);
            }, 20);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, '512');
            }, 0);
        },
        function () {
            return 32;
        }
    ];

parallel(taskList, function ( error, results ) {
    if ( !error ) {
        // results contains array of the given tasks execution results
        // [true, 256, '512', 32]
        console.log(results);
    }
});

serial

Run the functions in the tasks array in series, each one running once the previous function has completed. If any functions in the series pass an error to its callback, no more functions are run, and callback is immediately called with the value of the error. Otherwise, callback receives an array and hash of results when tasks have completed. Task function name is used to name the corresponding hash-table values. Task function can either use callback to specify error and result value or return result value immediately.

Online example:

var serial   = require('cjs-async/serial'),
    taskList = [
        function () {
            return 32;
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, true);
            }, 10);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, 256);
            }, 20);
        },
        function ( callback ) {
            setTimeout(function () {
                callback(null, '512');
            }, 0);
        }
    ];
    
serial(taskList, function ( error, results ) {
    if ( !error ) {
        // results contains array of the given tasks execution results
        // [32, true, 256, '512']
        console.log(results);
    }
});

Contribution

If you have any problems or suggestions please open an issue according to the contribution rules.

License

cjs-async is released under the MIT License.

Keywords

FAQs

Package last updated on 04 Aug 2018

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