serial.js

var x = {};
x.list = [];

x.add = function(f)
{
    x.list.push(f);
    return x;
};

x.clear = function()
{
    x.list = [];
    return x;
};

x.run = function(data, index)
{
    if(isNaN(index)){
        index = 0;
    }
    var sum = x.list.length;
    if(index == sum){
        x.list = [];
        return false;
    }
    else{
        x.list[index](
            data,
            function(){
                x.run(data, ++index);
            }
        );
    }
};

module.exports = x;

xxfaxy
1.6k 声望18 粉丝