Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Pool< R > Class Template Reference

#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 ()

Detailed Description

template<class R>
class nix::Pool< R >

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.

Member Typedef Documentation

◆ Factory

template<class R>
typedef fun<ref<R>()> nix::Pool< R >::Factory

A function that produces new instances of R on demand.

◆ Validator

template<class R>
typedef fun<bool(const ref<R> &)> nix::Pool< R >::Validator

A function that checks whether an instance of R is still usable. Unusable instances are removed from the pool.

Constructor & Destructor Documentation

◆ Pool()

template<class R>
nix::Pool< R >::Pool ( size_t max,
const Factory & factory,
const Validator & validator = [](ref<R> r) { return true; } )
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.


The documentation for this class was generated from the following files: