Nix 2.26.3
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 std::function< ref< R >()> Factory
 
typedef std::function< bool(const ref< R > &)> Validator
 

Public Member Functions

 Pool (size_t max=std::numeric_limits< size_t >::max(), const Factory &factory=[]() { return make_ref< R >();}, const Validator &validator=[](ref< R > r) { return true;})
 
void incCapacity ()
 
void decCapacity ()
 
Handle get ()
 
size_t count ()
 
size_t capacity ()
 
void flushBad ()
 

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 std::function<ref<R>()> nix::Pool< R >::Factory

A function that produces new instances of R on demand.

◆ Validator

template<class R>
typedef std::function<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.


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