From c3c266d0a7dba2e114f77c5a5442854c3454663c Mon Sep 17 00:00:00 2001 From: Archangel Date: Sun, 12 Jan 2025 15:52:28 +0100 Subject: [PATCH] Update promise in returnSingleBotFromCache --- project/src/controllers/BotController.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index eecb0aae5..16730c041 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -429,19 +429,18 @@ export class BotController { // Check cache for bot using above key if (!this.botGenerationCacheService.cacheHasBotWithKey(cacheKey)) { - const botPromises: Promise[] = []; - // No bot in cache, generate new and return one - for (let i = 0; i < botGenerationDetails.botCountToGenerate; i++) { - botPromises.push(this.generateSingleBotAndStoreInCache(botGenerationDetails, sessionId, cacheKey)); - } + // No bot in cache, generate new and store in cache + await Promise.all( + Array.from({ length: botGenerationDetails.botCountToGenerate }).map( + async () => await this.generateSingleBotAndStoreInCache(botGenerationDetails, sessionId, cacheKey), + ), + ); - await Promise.all(botPromises).then(() => { - this.logger.debug( - `Generated ${botGenerationDetails.botCountToGenerate} ${botGenerationDetails.role} (${ - botGenerationDetails.eventRole ?? "" - }) ${botGenerationDetails.botDifficulty} bots`, - ); - }); + this.logger.debug( + `Generated ${botGenerationDetails.botCountToGenerate} ${botGenerationDetails.role} (${ + botGenerationDetails.eventRole ?? "" + }) ${botGenerationDetails.botDifficulty} bots`, + ); } const desiredBot = this.botGenerationCacheService.getBot(cacheKey);