From d2dfbcfa9688016e6e32d22b3f69bdb9b0aae5e3 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 7 Mar 2024 20:04:37 -0300 Subject: [PATCH] Refactor processPictograms function to wait the pictonizaer response before send new request --- src/engine.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/engine.ts b/src/engine.ts index 5042494..146309d 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -214,18 +214,19 @@ async function pictonizer(imagePrompt: string): Promise { async function processPictograms( suggestions: Suggestion[] ): Promise { - const suggestionsWithAIImage = await Promise.all( - suggestions.map(async (suggestion) => { - if (suggestion.pictogram.isAIGenerated) { - const suggestionWithAIImage = { ...suggestion }; - suggestionWithAIImage.pictogram.images = [ - await pictonizer(suggestion.label), - ]; - return suggestionWithAIImage; - } - return suggestion; - }) - ); + const suggestionsWithAIImage: Suggestion[] = []; + + for (const suggestion of suggestions) { + if (suggestion.pictogram.isAIGenerated) { + const suggestionWithAIImage = { ...suggestion }; + suggestionWithAIImage.pictogram.images = [ + await pictonizer(suggestion.label), + ]; + suggestionsWithAIImage.push(suggestionWithAIImage); + } else { + suggestionsWithAIImage.push(suggestion); + } + } return suggestionsWithAIImage; }