Skip to content

Commit

Permalink
Allow deriving from connection pools
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Mar 1, 2024
1 parent 3d60a0c commit a74fb14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 8 additions & 2 deletions include/tao/pq/connection_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@

namespace tao::pq
{
class connection_pool final
class connection_pool
: public internal::pool< connection >
{
private:
const std::string m_connection_info;
std::optional< std::chrono::milliseconds > m_timeout;
std::function< poll::callback > m_poll;

protected:
[[nodiscard]] auto v_create() const -> std::unique_ptr< pq::connection > override;

[[nodiscard]] auto v_is_valid( connection& c ) const noexcept -> bool override
{
return c.is_idle();
}

private:
// pass-key idiom
class private_key final
{
Expand All @@ -46,7 +48,11 @@ namespace tao::pq
public:
connection_pool( const private_key /*unused*/, const std::string_view connection_info, std::function< poll::callback > poll_cb );

[[nodiscard]] static auto create( const std::string_view connection_info, std::function< poll::callback > poll_cb = internal::poll ) -> std::shared_ptr< connection_pool >;
template< typename T = connection_pool >
[[nodiscard]] static auto create( const std::string_view connection_info, std::function< poll::callback > poll_cb = internal::poll ) -> std::shared_ptr< T >
{
return std::make_shared< T >( private_key(), connection_info, std::move( poll_cb ) );
}

[[nodiscard]] auto timeout() const noexcept -> decltype( auto )
{
Expand Down
5 changes: 0 additions & 5 deletions src/lib/pq/connection_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ namespace tao::pq
m_poll( std::move( poll_cb ) )
{}

auto connection_pool::create( const std::string_view connection_info, std::function< poll::callback > poll_cb ) -> std::shared_ptr< connection_pool >
{
return std::make_shared< connection_pool >( private_key(), connection_info, std::move( poll_cb ) );
}

void connection_pool::set_timeout( const std::chrono::milliseconds timeout ) noexcept
{
m_timeout = timeout;
Expand Down

0 comments on commit a74fb14

Please sign in to comment.