New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hybridflows

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hybridflows

A hybrid module for asynchronous flow control with error handling and data forwarding

  • 0.2.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

hybridflows

A hybrid module for asynchronous flow control with error handling and data forwarding. Hybrid means the module can be used on server an client and thus requirejs is used as module loader. Please check jsdoc for detailed module documentation.

serial example


    requirejs([ 'require' ],function (require) {
    
        var hybridflows = require('hybridflows');

        // needed on server to enable setTimeout()
        var timers = require('timers');
        var seconds = 1000
        
        var serialTasks = [
        
            function (data, next) {
        
                setTimeout(function () {
        
                    data = data + 1;
                    next(null, data);
        
                }, 1 * seconds);
        
            }, function (data, next) {
        
                setTimeout(function () {
        
                    data = data + 2;
                    next(null, data);
                    //next(new Error('some error'));
        
                }, 2 * seconds);
        
            }, function (data, next) {
        
                setTimeout(function () {
        
                    data = data + 3;
                    next(null, data);
        
                }, 3 * seconds);
            }
        ];
        
        var serialOptions = {
        
            'tasks': serialTasks,
            'data': 0
        };
        
        hybridflows.serial(serialOptions, function (error, data) {
        
            if (error) {
        
                console.error('Serial: ' + error);
        
            } else {
        
                console.log('Serial: ' + data);
            }
        
        });
        
    });

parallel example


    requirejs([ 'require' ],function (require) {

        var hybridflows = require('hybridflows');
        
        // needed on server to enable setTimeout()
        var timers = require('timers');
        var seconds = 1000;
        
        var parallelTasks = [
        
            function (data, done) {
        
                setTimeout(function () {
        
                    data.push(1);
                    done();
        
                }, 1 * seconds);
        
            }, function (data, done) {
        
                setTimeout(function () {
        
                    data.push(2);
                    done();
                    //done(new Error('some error'));
        
                }, 2 * seconds);
        
            }, function (data, done) {
        
                setTimeout(function () {
        
                    data.push(3);
                    done();
        
                }, 3 * seconds);
            }
        ];
        
        var parallelOptions = {
        
            'tasks': parallelTasks,
            'data': []
        };
        
        hybridflows.parallel(parallelOptions, function (errors, data) {
        
            if (Array.isArray(errors)) {
        
                errors.forEach(function (error) {
        
                    console.error('Parallel: ' + error);
        
                });
        
            } else {
        
                var result = 0;
                data.forEach(function (number) {
        
                    result += number;
                });
        
                console.log('Parallel: ' + result);
        
            }
        });
        
    });


Keywords

FAQs

Package last updated on 26 Jun 2014

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