From 3781ac46311b35dd2d434b5332631a9bca90fe86 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Fri, 10 Nov 2023 11:59:52 +0200 Subject: [PATCH] docs: added troubleshooting guide for promise.all (#5586) * docs: added troubleshooting guide for promise.all * fix eslint errors --- .../troubleshooting/promise-all-rollback.md | 18 ++++++++++++++++++ www/apps/docs/sidebars.js | 5 +++++ 2 files changed, 23 insertions(+) create mode 100644 www/apps/docs/content/troubleshooting/promise-all-rollback.md diff --git a/www/apps/docs/content/troubleshooting/promise-all-rollback.md b/www/apps/docs/content/troubleshooting/promise-all-rollback.md new file mode 100644 index 0000000000..aede1e273c --- /dev/null +++ b/www/apps/docs/content/troubleshooting/promise-all-rollback.md @@ -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.... + ]) + } +} +``` diff --git a/www/apps/docs/sidebars.js b/www/apps/docs/sidebars.js index 4fb70c5acb..7a9f115b97 100644 --- a/www/apps/docs/sidebars.js +++ b/www/apps/docs/sidebars.js @@ -2098,6 +2098,11 @@ module.exports = { id: "troubleshooting/database-error", label: "Database Errors", }, + { + type: "doc", + id: "troubleshooting/promise-all-rollback", + label: "Database Transactions and Promise.all", + }, { type: "doc", id: "troubleshooting/redis-events",