Skip to content

Instantly share code, notes, and snippets.

@steveyen
Created October 2, 2015 18:42
Show Gist options
  • Save steveyen/718c93e7bc123bddd3ac to your computer and use it in GitHub Desktop.
Save steveyen/718c93e7bc123bddd3ac to your computer and use it in GitHub Desktop.
pool := make(chan thing, size)
func Get() {
t, ok := <-pool
if !ok { return PoolClosed }
return t
}
func Return(t) {
m.lock()
if !closed {
pool <- t
}
m.unlock()
}
func Close() {
m.lock()
if !closed {
close(pool)
}
closed = true
m.unlock()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment