Created
September 16, 2012 14:56
-
-
Save KlonD90/3732736 to your computer and use it in GitHub Desktop.
My Pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
create:function(){ | |
return { | |
poolLength:0, | |
free:[], | |
getId:function(){ | |
var id; | |
if(this.free.length == 0){ | |
id = ++this.poolLength; | |
} | |
else { | |
id = this.free.pop(); | |
} | |
return id; | |
}, | |
freeId:function(id){ | |
this.free.push(id); | |
}, | |
restart:function(){ | |
this.free=[]; | |
this.poolLength=0; | |
} | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment