Skip to content

Commit

Permalink
Add is_busy()
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 15, 2024
1 parent b726879 commit 35774de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/tao/pq/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ namespace tao::pq
return transaction_status() == transaction_status::idle;
}

[[nodiscard]] auto is_busy() const noexcept -> bool;

[[nodiscard]] auto direct() -> std::shared_ptr< pq::transaction >;

[[nodiscard]] auto transaction() -> std::shared_ptr< pq::transaction >;
Expand Down
10 changes: 8 additions & 2 deletions src/lib/pq/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ namespace tao::pq
auto connection::get_result( const std::chrono::steady_clock::time_point end ) -> std::unique_ptr< PGresult, decltype( &PQclear ) >
{
bool wait_for_write = true;
while( PQisBusy( m_pgconn.get() ) != 0 ) {
while( is_busy() ) {
if( wait_for_write ) {
switch( PQflush( m_pgconn.get() ) ) {
case 0:
Expand All @@ -289,7 +289,8 @@ namespace tao::pq
break;

default:
throw std::runtime_error( std::format( "PQflush() failed: {}", error_message() ) ); // LCOV_EXCL_STOP
throw std::runtime_error( std::format( "PQflush() failed: {}", error_message() ) );
// LCOV_EXCL_STOP
}
}
connection::wait( wait_for_write, end );
Expand Down Expand Up @@ -502,6 +503,11 @@ namespace tao::pq
}
}

auto connection::is_busy() const noexcept -> bool
{
return PQisBusy( m_pgconn.get() ) != 0;
}

auto connection::direct() -> std::shared_ptr< pq::transaction >
{
return std::make_shared< internal::autocommit_transaction >( shared_from_this() );
Expand Down

0 comments on commit 35774de

Please sign in to comment.