(self, callback: F)
| 94 | /// encountering an error if it fails |
| 95 | #[instrument(level = "trace", skip(callback))] |
| 96 | pub(crate) async fn run<F, T, E>(self, callback: F) -> Result<T, TransactionError<E>> |
| 97 | where |
| 98 | F: for<'b> FnOnce( |
| 99 | &'b DatabaseTransaction, |
| 100 | ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'b>> |
| 101 | + Send, |
| 102 | T: Send, |
| 103 | E: std::fmt::Display + std::fmt::Debug + Send, |
| 104 | { |
| 105 | let res = callback(&self).await.map_err(TransactionError::Transaction); |
| 106 | if res.is_ok() { |
| 107 | self.commit().await.map_err(TransactionError::Connection)?; |
| 108 | } else { |
| 109 | self.rollback() |
| 110 | .await |
| 111 | .map_err(TransactionError::Connection)?; |
| 112 | } |
| 113 | res |
| 114 | } |
| 115 | |
| 116 | /// Commit a transaction atomically |
| 117 | #[instrument(level = "trace")] |
no test coverage detected