lockmethod

lock method for node.js

lock method for node.js

Install

npm install lockmethod

Example

var lockmethod  =  require('lockmethod');

    var time = 3000;    

    var obj = { changeState  :  lockmethod(
        function(state,cb){
            setTimeout(function(){
                cb(state+time)      
            },time) 
            time -= 300;
        }
    )
    }

    obj.changeState('a',function(r){console.log(r);});
    obj.changeState('b',function(r){console.log(r);});
    obj.changeState('c',function(r){console.log(r);});

    result is >>>  

        a2700
        b2400
        c2100
        

    IF: 

    var obj = { changeState  :  
        function(state,cb){
            setTimeout(function(){
                cb(state+time)      
            },time) 
            time -= 300;
        }
    }

    Then result is >>>

        c2100
        b2100
        a2100