Skip to content

Commit 35774de

Browse files
committed
Add is_busy()
1 parent b726879 commit 35774de

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/tao/pq/connection.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ namespace tao::pq
150150
return transaction_status() == transaction_status::idle;
151151
}
152152

153+
[[nodiscard]] auto is_busy() const noexcept -> bool;
154+
153155
[[nodiscard]] auto direct() -> std::shared_ptr< pq::transaction >;
154156

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

src/lib/pq/connection.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ namespace tao::pq
277277
auto connection::get_result( const std::chrono::steady_clock::time_point end ) -> std::unique_ptr< PGresult, decltype( &PQclear ) >
278278
{
279279
bool wait_for_write = true;
280-
while( PQisBusy( m_pgconn.get() ) != 0 ) {
280+
while( is_busy() ) {
281281
if( wait_for_write ) {
282282
switch( PQflush( m_pgconn.get() ) ) {
283283
case 0:
@@ -289,7 +289,8 @@ namespace tao::pq
289289
break;
290290

291291
default:
292-
throw std::runtime_error( std::format( "PQflush() failed: {}", error_message() ) ); // LCOV_EXCL_STOP
292+
throw std::runtime_error( std::format( "PQflush() failed: {}", error_message() ) );
293+
// LCOV_EXCL_STOP
293294
}
294295
}
295296
connection::wait( wait_for_write, end );
@@ -502,6 +503,11 @@ namespace tao::pq
502503
}
503504
}
504505

506+
auto connection::is_busy() const noexcept -> bool
507+
{
508+
return PQisBusy( m_pgconn.get() ) != 0;
509+
}
510+
505511
auto connection::direct() -> std::shared_ptr< pq::transaction >
506512
{
507513
return std::make_shared< internal::autocommit_transaction >( shared_from_this() );

0 commit comments

Comments
 (0)