lockmethod

lock method for node.js

npm install lockmethod
4 downloads in the last day
119 downloads in the last week
278 downloads in the last month

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
npm loves you