| 189 | } |
| 190 | |
| 191 | function unregisterTransaction(tx: Transaction<any>) { |
| 192 | // Always flush pending work for this transaction before removing it from |
| 193 | // the ambient stack – this runs even if the mutate callback throws. |
| 194 | // If flush throws (e.g., due to a job error), we still clean up the stack. |
| 195 | try { |
| 196 | transactionScopedScheduler.flush(tx.id) |
| 197 | } finally { |
| 198 | transactionStack = transactionStack.filter((t) => t.id !== tx.id) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | function removeFromPendingList(tx: Transaction<any>) { |
| 203 | const index = transactions.findIndex((t) => t.id === tx.id) |