Skip to content

Instantly share code, notes, and snippets.

@KlonD90
Created September 16, 2012 14:56
Show Gist options
  • Save KlonD90/3732736 to your computer and use it in GitHub Desktop.
Save KlonD90/3732736 to your computer and use it in GitHub Desktop.
My Pool
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