docs: added troubleshooting guide for promise.all (#5586)
* docs: added troubleshooting guide for promise.all * fix eslint errors
This commit is contained in:
1 parent
03e56aed74
commit
3781ac4631
2 files changed
+23
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
# Database Transaction Not Rolling Back When Promise.all is Used
|
||||||
|
|
||||||
|
Due to how `Promise.all` works, when you run multiple database transactions within it, these transactions may not be rolled back when an error occurs.
|
||||||
|
|
||||||
|
To mitigate this issue, use the `promiseAll` function which can be imported from `@medusajs/utils`. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { promiseAll } from "@medusajs/utils"
|
||||||
|
import { TransactionBaseService } from "@medusajs/medusa"
|
||||||
|
|
||||||
|
class MyService extends TransactionBaseService {
|
||||||
|
async performTransactions() {
|
||||||
|
return await promiseAll([
|
||||||
|
// your transactions....
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -2098,6 +2098,11 @@ module.exports = {
|
|||||||
id: "troubleshooting/database-error",
|
id: "troubleshooting/database-error",
|
||||||
label: "Database Errors",
|
label: "Database Errors",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "doc",
|
||||||
|
id: "troubleshooting/promise-all-rollback",
|
||||||
|
label: "Database Transactions and Promise.all",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "doc",
|
type: "doc",
|
||||||
id: "troubleshooting/redis-events",
|
id: "troubleshooting/redis-events",
|
||||||
|
|||||||
Reference in new issue
Block a user