Skip to content

Commit

Permalink
fix: handle promises for external resources
Browse files Browse the repository at this point in the history
  • Loading branch information
QRuhier committed Oct 11, 2024
1 parent 9ec4c43 commit 6b441fc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions drama-queen/src/core/usecases/synchronizeData/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ export const thunks = {
)

// add in cache the missing external resources for needed questionnaires
await Promise.all(
neededQuestionnaires.map((questionnaire) => {
getResourcesFromExternalQuestionnaire(
const prGetExternalResources = Promise.all(
neededQuestionnaires.map(async (questionnaire) => {
await getResourcesFromExternalQuestionnaire(
externalResourcesUrl,
questionnaire
).then(() =>
Expand All @@ -216,16 +216,24 @@ export const thunks = {
)

// delete the cache of every not needed external questionnaires
await Promise.all(
const prDeleteExternalResources = Promise.all(
notNeededQuestionnaires.map((questionnaire) =>
caches.delete(questionnaire.cacheName)
)
)

// delete the root-cache of external resources if no external questionnaire is needed
if (neededQuestionnaires.length === 0) {
await caches.delete(externalResourcesRootCacheName)
}
const prDeleteExternalRootCache =
neededQuestionnaires.length === 0
? caches.delete(externalResourcesRootCacheName)
: Promise.resolve()

// We await untill the promises for external resources are finished
await Promise.all([
prGetExternalResources,
prDeleteExternalResources,
prDeleteExternalRootCache,
])
}

//We await untill all the promises are finished
Expand Down

0 comments on commit 6b441fc

Please sign in to comment.