![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include <pool.hh>
Classes | |
| class | Handle |
Public Types | |
| typedef fun< ref< R >()> | Factory |
| typedef fun< bool(const ref< R > &)> | Validator |
Public Member Functions | |
| Pool (size_t max, const Factory &factory, const Validator &validator=[](ref< R > r) { return true;}) | |
| void | incCapacity () |
| void | decCapacity () |
| Handle | get () |
| size_t | count () |
| size_t | capacity () |
| void | flushBad () |
| std::vector< ref< R > > | clear () |
This template class implements a simple pool manager of resources of some type R, such as database connections. It is used as follows:
class Connection { ... };
Pool<Connection> pool;
{ auto conn(pool.get()); conn->exec("select ..."); }
Here, the Connection object referenced by ‘conn’ is automatically returned to the pool when ‘conn’ goes out of scope.
A function that produces new instances of R on demand.
A function that checks whether an instance of R is still usable. Unusable instances are removed from the pool.
|
inline |
Note: factory cannot have a default argument because the default would be instantiated when Pool<R> is instantiated, requiring R to be default-constructible.