A thread-safe connection pool for managing reusable database client connections.
More...
#include <ConnectionPool.hpp>
|
| using | ClientFactory = std::function< std::shared_ptr< ClientType >()> |
| |
|
| | ConnectionPool (size_t max_size, ClientFactory factory) |
| | Constructs a new ConnectionPool.
|
| |
| void | init (std::function< void(std::shared_ptr< ClientType >, std::function< void(bool)>)> connector, std::function< void(bool success)> on_ready) |
| | Initializes the pool by establishing the initial set of connections.
|
| |
| void | acquire (std::function< void(std::shared_ptr< ClientType >)> callback) |
| | Acquires a database connection asynchronously from the pool.
|
| |
| void | release (std::shared_ptr< ClientType > client) |
| | Releases a connection back to the pool.
|
| |
template<typename ClientType>
class database::ConnectionPool< ClientType >
A thread-safe connection pool for managing reusable database client connections.
- Template Parameters
-
| ClientType | The type of database client to manage. |
◆ ClientFactory
template<typename ClientType >
◆ ConnectionPool()
template<typename ClientType >
Constructs a new ConnectionPool.
- Parameters
-
| max_size | The maximum number of connections to maintain in the pool. |
| factory | A callable that creates new instances of ClientType. |
◆ acquire()
template<typename ClientType >
Acquires a database connection asynchronously from the pool.
- Parameters
-
| callback | Callback invoked with a shared pointer to a ready client when available. |
◆ init()
template<typename ClientType >
| void database::ConnectionPool< ClientType >::init |
( |
std::function< void(std::shared_ptr< ClientType >, std::function< void(bool)>)> |
connector, |
|
|
std::function< void(bool success)> |
on_ready |
|
) |
| |
|
inline |
Initializes the pool by establishing the initial set of connections.
- Parameters
-
| connector | A function used to connect a client asynchronously. |
| on_ready | Callback invoked when the pool is initialized. The parameter is true if initialization was successful. |
◆ release()
template<typename ClientType >
Releases a connection back to the pool.
- Parameters
-
| client | The client to return to the pool. |
The documentation for this class was generated from the following file: