Closed tanner0101 closed 5 years ago
In case you are interested, here's my current thread-safe "resource pool" implementation with pruning. Working well in practice, but would need some adaptations for Vapor, of course: https://gist.github.com/MrMage/6fe071f405ac2c1b8a4cde25f05061db
Surprisingly, it is actually shorter than the Vapor one even though it supports pruning (mostly due to the lack of documentation, I guess).
I ended up going with a while
loop that I think will do the job: https://github.com/vapor/async-kit/blob/master/Sources/AsyncKit/ConnectionPool.swift#L214-L226
The connection pool currently replaces closed available connections by replacing them when they are requested. This means that once a pool's active connection count increases, it will never decrease.
It would be better to check the available connections list first for any open connections before attempting to open a new replacement.