Coder Social home page Coder Social logo

node-exec's Introduction

NodeJs

nodejs并行、串行编码框架 serial、parallel code module for nodejs



1、LinkedList
the linked-list module based on basic link-list
基于基础链表的上层封装(the linked-list module based on basic link-list)
双向链表,支持基本的操作,亦可用作队列



2、Exec
parallel serial execute functions
并行、串行执行一系列方法

//并行串行执行模块
//参数请自己遵守约束,减少检测,提高性能
_Exec.parallel({fns: [func1, func2, func3], args: [null, null, {game_id: 1}], errorBack: errorCall, overBack: overCall});
_Exec.serial({fns: [func1, func2, func3], args: [null, null, {game_id: 1}], errorBack: errorCall, overBack: overCall});

//并行parallel:自定义function的arguments[0]必有如下参数:callBack:自定义函数执行完毕后callBack(null,results) 或者 callBack(error)-此时后面的函数将不会在执行;arg:自定义参数,可空

//串行serial:自定义function的arguments[0]必有如下参数:pre_results:上一个函数的执行结果;callBack:自定义函数执行完毕后callBack(null,results) 或者 callBack(error)-此时后面的函数将不会在执行;arg:自定义参数,可空

使用eg:

require('exec');
function func1() {
    var params = arguments[0];
    setTimeout(function () {
        params && params.callback(null, '1');
    }, 3000);
}
function func2() {
    var params = arguments[0];
    setTimeout(function () {
        params && params.callback(null, +'2');
    }, 2000);
}
function func3() {
    var params = arguments[0];
    setTimeout(function () {
        params && params.callback(null, '3');
    }, 1000);
}

function errorCall(err) { console.log('error:' + err); }

function overCall(results) { console.timeEnd('1'); console.log('over:' + results); }

console.time('1'); _Exec.parallel({ fns: [func1, func2, func3], args: [null, null, {game_id: 10002266}], errorBack: errorCall, overBack: overCall });

_Exec.serial({ fns: [func1, func2, func3], args: [null, null, {game_id: 10002266}], errorBack: errorCall, overBack: overCall });



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.