Skip to content

Instantly share code, notes, and snippets.

@kevinresol
Created October 9, 2016 05:30
Show Gist options
  • Save kevinresol/267f3557ebad1df25447c3f0e9b12fe7 to your computer and use it in GitHub Desktop.
Save kevinresol/267f3557ebad1df25447c3f0e9b12fe7 to your computer and use it in GitHub Desktop.
Just a pool
class Pool<T> {
var pool:Array<T>;
var factory:Void->T;
public function new(factory) {
this.factory = factory;
pool = [];
}
public function get() {
if(pool.length == 0) return factory();
return pool.pop();
}
public function put(v:T) {
pool.push(T);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment