Open bmatsuo opened 7 years ago
I would probably just use a buffered channel. You won't be able to implement faster acquire / release, and draining the pool is relatively straightforward. Users will have to specify a limit for the pool, but I think that is good. As you have pointed out, you can get into a situation where a Copy() call fails / blocks forever since all slots are taken. Therefore the right size for the free list depends on the application, which only the user knows.
A proper free list of Txns should probably not use sync.Pool for its underlying storage. It can work for some applications, which I have tried to clearly explain in the documentation. But some of sync.Pool's behaviors are not conducive to effectively managing a Txn free list. For example, there is no guarantee that a single goroutine can flush all cached objects from a sync.Pool.
This issue is meant to hold the discussion of how a free list that does not rely on sync.Pool may be implemented.
This issue was brought up initially in a comment by @lmb on #104. Full background can be found by reading that thread. But this comment summarizes the general outcome of the discussion.