Skip to content

Instantly share code, notes, and snippets.

@Makio64
Created December 21, 2015 13:49
Show Gist options
  • Save Makio64/7422170c0b7b2682c46d to your computer and use it in GitHub Desktop.
Save Makio64/7422170c0b7b2682c46d to your computer and use it in GitHub Desktop.
Utility class to manage pool of objects
# Utility class to manage pool of objects
class ObjectPool
constructor: (@create, @minSize, @maxSize) ->
@list = []
for [0...@minSize]
@add()
return
add: () ->
return @list.push @create()
checkOut: () ->
if @list.length == 0
return @create()
else
return @list.pop()
checkIn: (item) ->
if @list.length < @maxSize
@list.push item
return
module.exports = ObjectPool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment