Skip to main content

Module tx

Module tx 

Source
Expand description

Request-scoped transactions for #[Transactional].

§Contract

  • begin on entering the handler, against the primary of the request-tenant’s pool.
  • Commit when the handler returns Ok(..).
  • Rollback when it returns Err(..) — and on panic / #[Timeout] expiry, because dropping an uncommitted driver transaction rolls back in every supported ecosystem.

§Zero-lock mechanics

The live transaction rides a tokio::task_local! slot — strictly per-request-task state, no global registry, no mutex. Services reach it through with_current_tx, which takes the transaction out of the slot, awaits the closure, and puts it back — so no RefCell borrow is ever held across an .await (keeping handler futures Send).

Diesel’s sync core cannot hold a transaction across .await by design; #[Transactional] therefore rejects Diesel-backed pools at runtime with a clear error — use DieselBlockingPool::transaction (whole tx inside one blocking closure) instead.

Enums§

ArclyTransaction
One live driver transaction. Dropping without commit rolls back.

Functions§

in_transaction
true when running inside a #[Transactional] scope.
with_current_tx
Run work with this request’s transaction (if #[Transactional] opened one). The transaction is moved out of the slot for the duration of the closure and put back afterwards, so the future stays Send.