Created
October 9, 2016 05:30
-
-
Save kevinresol/267f3557ebad1df25447c3f0e9b12fe7 to your computer and use it in GitHub Desktop.
Just a 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
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