Created
October 2, 2015 18:42
-
-
Save steveyen/718c93e7bc123bddd3ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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