|
Lightweight 0.20260617.0
|
#include <AsyncSqlTransaction.hpp>
Public Member Functions | |
| AsyncSqlTransaction (SqlConnection &connection) noexcept | |
| AsyncSqlTransaction (AsyncSqlTransaction const &)=delete | |
| AsyncSqlTransaction & | operator= (AsyncSqlTransaction const &)=delete |
| AsyncSqlTransaction (AsyncSqlTransaction &&)=delete | |
| AsyncSqlTransaction & | operator= (AsyncSqlTransaction &&)=delete |
| ~AsyncSqlTransaction () | |
| Best-effort synchronous finalization if still open (see class note). | |
| Task< void > | BeginAsync (SqlTransactionMode defaultMode=SqlTransactionMode::COMMIT, SqlIsolationMode isolationMode=SqlIsolationMode::DriverDefault, std::stop_token token={}) |
| Task< void > | CommitAsync () |
| Task< void > | RollbackAsync () |
A distinct coroutine-based SQL transaction.
Unlike the high- and low-level async methods (which are added directly to the existing classes), a transaction is a scoped object, so it reads best as its own type. Each operation is offloaded to the connection's async backend (a worker thread, serialized per connection) and the awaiting coroutine resumes on the app's resume scheduler.
The underlying connection must have async enabled (SqlConnection::EnableAsync) before use and must stay async-enabled and alive for the whole lifetime of the transaction: do not destroy the connection (or return the owning pooled DataMapper, which disables async) between BeginAsync and the matching CommitAsync / RollbackAsync — the offloaded steps capture the connection by pointer and would otherwise fail (a clear std::logic_error from SqlConnection::AsyncBackend) or dangle.
Always co_await CommitAsync() or co_await RollbackAsync() explicitly. If the transaction is still open when destroyed, the destructor performs a best-effort finalization (per the configured mode) and emits a warning via SqlLogger. That finalization is itself routed through the connection's strand (and blocks the destroying thread until it completes) so it never touches the ODBC handle concurrently with another in-flight async operation on the same connection.
Definition at line 55 of file AsyncSqlTransaction.hpp.
|
explicitnoexcept |
Constructs an (not-yet-begun) async transaction over connection.
| connection | The async-enabled connection to run the transaction on. |
| Task< void > Lightweight::Async::AsyncSqlTransaction::BeginAsync | ( | SqlTransactionMode | defaultMode = SqlTransactionMode::COMMIT, |
| SqlIsolationMode | isolationMode = SqlIsolationMode::DriverDefault, |
||
| std::stop_token | token = {} |
||
| ) |
Asynchronously begins the transaction (disables auto-commit).
| defaultMode | How an un-finalized transaction is closed on destruction. Defaults to COMMIT to match the synchronous SqlTransaction, so porting sync code that relies on commit-on-scope-exit does not silently switch to rollback. |
| isolationMode | The transaction isolation level. |
| token | Optional cancellation token (a default-constructed std::stop_token is non-cancellable; cancellation is checked before the step is dispatched). |
| std::logic_error | if a transaction is already open on this object (programmer error). |
| Task< void > Lightweight::Async::AsyncSqlTransaction::CommitAsync | ( | ) |
Asynchronously commits the transaction.
| Task< void > Lightweight::Async::AsyncSqlTransaction::RollbackAsync | ( | ) |
Asynchronously rolls back the transaction.